summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelianthella <git@gumi.ca>2021-01-16 15:55:15 -0500
committerHelianthella <git@gumi.ca>2021-01-16 21:23:58 -0500
commit66a8771528e428cac602999a0ce25d8a7f9cf760 (patch)
tree5e509cf34f5db1261a504090c4643032492808b6
parenta0b124bc80ead9733452638d25895a6522f5f2f0 (diff)
downloadpolicies-66a8771528e428cac602999a0ce25d8a7f9cf760.tar.gz
policies-66a8771528e428cac602999a0ce25d8a7f9cf760.tar.bz2
policies-66a8771528e428cac602999a0ce25d8a7f9cf760.tar.xz
policies-66a8771528e428cac602999a0ce25d8a7f9cf760.zip
[ci skip] improve path aliasing
-rw-r--r--policies/constitution.md2
-rw-r--r--policies/forum-rules.md1
-rw-r--r--policies/game-rules.md2
-rw-r--r--policies/social-convention.md2
-rw-r--r--src/build.ts74
5 files changed, 61 insertions, 20 deletions
diff --git a/policies/constitution.md b/policies/constitution.md
index 2ca8822..36915fe 100644
--- a/policies/constitution.md
+++ b/policies/constitution.md
@@ -1,7 +1,7 @@
---
name: The Mana World Team (TMWT)
description: Constitution of The Mana World
-aliases: [TMWC, TMWT, organization, organisation, org]
+aliases: [TMWC, TMWT, team, tmw_team, committee, tmw_committee, collective, tmw_collective, organization, organisation, org]
autoupdate:
forums: {forum: 1, topic: 17166, post: 132138}
diff --git a/policies/forum-rules.md b/policies/forum-rules.md
index dab8f2b..52bb724 100644
--- a/policies/forum-rules.md
+++ b/policies/forum-rules.md
@@ -1,6 +1,7 @@
---
name: Forum Rules
description: Rules observed on the forums
+aliases: [forum, forums]
autoupdate:
forums: {forum: 1, topic: 2922, post: 25061}
diff --git a/policies/game-rules.md b/policies/game-rules.md
index 4832ddc..26838a6 100644
--- a/policies/game-rules.md
+++ b/policies/game-rules.md
@@ -1,7 +1,7 @@
---
name: Game Rules
description: Rules observed in-game
-aliases: [rules]
+aliases: [rules, game]
autoupdate:
forums: {forum: 1, topic: 2922, post: 25061}
diff --git a/policies/social-convention.md b/policies/social-convention.md
index 7321808..34e33fc 100644
--- a/policies/social-convention.md
+++ b/policies/social-convention.md
@@ -1,7 +1,7 @@
---
name: TMW Social Convention (TSC)
description: Guidelines for social interaction
-aliases: [TSC, ESC]
+aliases: [TSC, ESC, social, convention, tmw-social-convention, evol-social-convention]
autoupdate:
wiki: TMW_Social_Convention
diff --git a/src/build.ts b/src/build.ts
index 772570f..bf9de2f 100644
--- a/src/build.ts
+++ b/src/build.ts
@@ -22,6 +22,7 @@ interface PolicyYFM {
const decoder = new TextDecoder("utf-8");
const encoder = new TextEncoder();
+/** the source of the index page */
const index = {
prefix: `
<!doctype html>
@@ -42,8 +43,13 @@ const index = {
`.trim(), list: "", suffix: "</ul>\n</nav>\n</main>\n</body>\n</html>"
};
-// the _redirects file used by netlify
-let redirects = "";
+/** the _redirects file used by netlify */
+let _redirects = "";
+/** the [routes] portion of the yaml file used by Render */
+let render_yaml = "";
+
+/** a map of all generated path aliases */
+const routes: Map<string, Set<string>> = new Map();
console.info(">> Building the static site...");
@@ -52,7 +58,7 @@ await Deno.remove("build", { recursive: true });
// loop through policy files
for await (const dirEntry of Deno.readDir("policies")) {
- const file = dirEntry.name;
+ const file: string = dirEntry.name;
const [shortName, type] = file.split(".");
if (type.toLowerCase() !== "md") {
@@ -79,26 +85,50 @@ for await (const dirEntry of Deno.readDir("policies")) {
index.list += `<li><a href="/${shortName}" title="${YFM.description}" aria-label="${YFM.description}">${YFM.name}</a></li>\n`;
// add to the netlify redirect file
- redirects += `/${shortName} /${shortName}/index.html 200!\n`;
+ _redirects += `/${shortName} /${shortName}/index.html 200!\n`;
+
+ /** a Set<string> of all aliases for this policy */
+ const aliases: Set<string> = new Set(Reflect.has(YFM, "aliases") ? YFM.aliases : []);
+
+ /** generates aliases from common path substitutions */
+ const generateCommonAliases = (path: string) => {
+ const substitutions = [
+ ["-", "_"],
+ ["_", "-"],
+ ["-"],
+ ["_"],
+ ];
+
+ for (const substitution of substitutions) {
+ const replacement = path.replace(substitution[0], substitution[1] ?? "");
+ aliases.add(replacement);
+ aliases.add(replacement.toLowerCase());
+ }
+
+ // lower case
+ aliases.add(path.toLowerCase());
+ };
// built-in aliases
- if (shortName != shortName.replace("-", "_")) {
- redirects += `/${shortName.replace("-", "_")} /${shortName} 302\n`;
- } if (shortName != shortName.replace("-", "")) {
- redirects += `/${shortName.replace("-", "")} /${shortName} 302\n`;
+ generateCommonAliases(shortName);
+
+ // process path aliases (and duplicate before iterating)
+ for (const alias of new Set(aliases)) {
+ generateCommonAliases(alias);
}
- // process path aliases
- if (Reflect.has(YFM, "aliases")) {
- for (const alias of YFM.aliases as string[]) {
- redirects += `/${alias} /${shortName} 302\n`;
+ // make sure we don't include the article itself in its alias Set
+ aliases.delete(shortName);
- if (alias != alias.toLowerCase()) {
- redirects += `/${alias.toLocaleLowerCase()} /${shortName} 302\n`;
- }
- }
+ // add all aliases to the netlify _redirects file and the Render yaml file
+ for (const alias of aliases) {
+ _redirects += `/${alias} /${shortName} 302\n`
+ render_yaml += `- type: redirect\n source: /${alias}\n destination: /${shortName}\n`;
}
+ // record the aliases in the global routes map
+ routes.set(shortName, aliases);
+
// wrap the generated html inside our template
const policyPage = encoder.encode(`
<!doctype html>
@@ -132,7 +162,17 @@ const indexPage = encoder.encode(index.prefix + index.list + index.suffix);
await Deno.writeFile("build/index.html", indexPage, {create: true});
// write the _redirects file (netlify)
-await Deno.writeFile("build/_redirects", encoder.encode(redirects), {create: true});
+await Deno.writeFile("build/_redirects", encoder.encode(_redirects), {create: true});
+
+// write the render.yaml file (render)
+await Deno.writeFile("build/render.yaml", encoder.encode(render_yaml), {create: true});
+
+// write the routes.json file (generic)
+const routes_obj: any = {};
+for (const [route, aliases] of routes) {
+ routes_obj[route] = [...aliases]; // convert the Map
+}
+await Deno.writeFile("build/routes.json", encoder.encode(JSON.stringify(routes_obj)), {create: true});
// copy static assets
for await (const dirEntry of Deno.readDir("src/static")) {