Skip to content

Commit f5d79fb

Browse files
committed
Fix faq-updater for new types of links
1 parent fcf0e11 commit f5d79fb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

.github/faq-updater/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Client } from "discord.js";
22
import { readFile } from "node:fs/promises";
3+
import path from "node:path";
34

45
const client = new Client({
56
intents: [],
@@ -107,25 +108,33 @@ function splitMessage(message) {
107108
}
108109

109110
async function getNewMessages() {
110-
const rawContent = await readFile("../../wiki/FAQ.md", "utf8");
111-
const [_frontmatter, rawQuestions] = rawContent.split("# FAQ", 2).map((section) => section.trim());
111+
const faqPath = "../../wiki/FAQ.md";
112+
const rawContent = await readFile(faqPath, "utf8");
113+
const [_frontmatter, rawQuestions] = rawContent
114+
.split("# FAQ", 2)
115+
.map((section) => section.trim());
116+
const baseUrl = "https://bluemap.bluecolored.de";
112117
return rawQuestions
113-
.replace(/{{site.baseurl}}/g, "https://bluemap.bluecolored.de")
118+
.replace(/{{site.baseurl}}/g, baseUrl)
114119
.split(/^###? /m)
115120
.slice(1)
116121
.flatMap((question) => {
117122
const [title, ...lines] = question.trim().split("\n");
118123
const content = lines
119124
.join("\n")
120125
.trimEnd()
121-
.replace(/\n{2,}/g, s => "<br>".repeat(s.length))
122-
.replace(/\s{2,}\n|\s*\\\n|\s*\n(?=\s*-)/g,"<br>")
123-
.replace(/\n\s*/g," ")
126+
.replace(/\n{2,}/g, (s) => "<br>".repeat(s.length))
127+
.replace(/\s{2,}\n|\s*\\\n|\s*\n(?=\s*-)/g, "<br>")
128+
.replace(/\n\s*/g, " ")
124129
.replace(/<br>/g, "\n")
125130
.replace(/\[([^\]]+)]\(([^)]+)\)/g, (_match, name, link) => {
126131
if (name === link) return `<${link}>`;
127132
if (link.startsWith("https://discord.com/channels/")) return link;
128-
if (link.startsWith("#")) return name;
133+
if (link.startsWith("#")) return `[${name}](<${baseUrl}/wiki/FAQ.html${link}>)`;
134+
if (link.startsWith("."))
135+
return `[${name}](<${baseUrl}/${path
136+
.relative("../../", path.join(path.dirname(faqPath), link))
137+
.replace(/\.md/, ".html")}>)`;
129138
return `[${name}](<${link}>)`;
130139
});
131140
const message = `## ${title}\n${content}`;

0 commit comments

Comments
 (0)