|
1 | 1 | import { Client } from "discord.js"; |
2 | 2 | import { readFile } from "node:fs/promises"; |
| 3 | +import path from "node:path"; |
3 | 4 |
|
4 | 5 | const client = new Client({ |
5 | 6 | intents: [], |
@@ -107,25 +108,33 @@ function splitMessage(message) { |
107 | 108 | } |
108 | 109 |
|
109 | 110 | 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"; |
112 | 117 | return rawQuestions |
113 | | - .replace(/{{site.baseurl}}/g, "https://bluemap.bluecolored.de") |
| 118 | + .replace(/{{site.baseurl}}/g, baseUrl) |
114 | 119 | .split(/^###? /m) |
115 | 120 | .slice(1) |
116 | 121 | .flatMap((question) => { |
117 | 122 | const [title, ...lines] = question.trim().split("\n"); |
118 | 123 | const content = lines |
119 | 124 | .join("\n") |
120 | 125 | .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, " ") |
124 | 129 | .replace(/<br>/g, "\n") |
125 | 130 | .replace(/\[([^\]]+)]\(([^)]+)\)/g, (_match, name, link) => { |
126 | 131 | if (name === link) return `<${link}>`; |
127 | 132 | 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")}>)`; |
129 | 138 | return `[${name}](<${link}>)`; |
130 | 139 | }); |
131 | 140 | const message = `## ${title}\n${content}`; |
|
0 commit comments