diff --git a/astro/wiki/src/pages/[...slug].astro b/astro/wiki/src/pages/[...slug].astro index 23bc196..bf16331 100644 --- a/astro/wiki/src/pages/[...slug].astro +++ b/astro/wiki/src/pages/[...slug].astro @@ -2,10 +2,9 @@ import fs from "node:fs"; import path from "node:path"; -const WIKI_DIR = path.resolve("../../docs/wiki"); -const EXCLUDE = [".git", "index.md"]; - export function getStaticPaths() { + const WIKI_DIR = path.resolve("src/content"); + const EXCLUDE = [".git", "index.md"]; function walk(dir, prefix = "") { const entries = fs.readdirSync(dir, { withFileTypes: true }); const slugs = []; @@ -25,6 +24,7 @@ export function getStaticPaths() { } const { slug } = Astro.params; +const WIKI_DIR = path.resolve("src/content"); const filePath = path.join(WIKI_DIR, `${slug}.md`); if (!fs.existsSync(filePath)) { @@ -33,7 +33,6 @@ if (!fs.existsSync(filePath)) { const raw = fs.readFileSync(filePath, "utf-8"); -// Parse frontmatter let content = raw; let frontmatter = {}; if (raw.startsWith("---")) { @@ -48,46 +47,28 @@ if (raw.startsWith("---")) { } } -// Detect locale from slug prefix -const isSl = slug.startsWith("sl/"); -const locale = isSl ? "sl" : "en"; -const base = isSl ? "/sl/" : "/"; +const title = (frontmatter.title || content.match(/^#\s+(.+)$/m)?.[1] || slug).replace(/^["']|["']$/g, ""); -// Resolve relative wiki links with locale prefix -// ./page.md → /page/ or /sl/page/ -// ../packaging/x → /../packaging/x (pass through absolute-ish paths) -const resolveLinks = (md) => - md.replace(/\]\(\.\/([^)]+)\.md\)/g, `](${base}$1/)`) - .replace(/\]\(\.\.\/([^)]+)\)/g, "](/$1)"); +// Resolve wiki links [label](./page.md) → [/page/] +content = content.replace(/\]\(\.\/([^)]+)\.md\)/g, "](/$1/)") + .replace(/\]\(\.\.\/([^)]+)\.md\)/g, "](/$1/)"); -content = resolveLinks(content); +// Fenced code blocks +content = content.replace(/```(\w*)\n([\s\S]*?)```/g, (_, lang, code) => + `
${code.trim()}`);
-// Resolve cross-wiki locale links: [label](./sl/page.md) → [/sl/page/]
-content = content.replace(/\]\(\.\/sl\/([^)]+)\.md\)/g, "](/sl/$1/)");
+// Tables
+content = content.replace(/\|(.+)\|\n\|[-| ]+\|\n((?:\|.+\|\n?)*)/gm, (_, header, rows) => {
+ const hcells = header.split("|").map(c => c.trim()).filter(Boolean);
+ const thead = `${code.trim()}`;
- });
-
-content = renderCode(content);
-
-// Render tables
-const renderTables = (md) => {
- return md.replace(/\|(.+)\|\n\|[-| ]+\|\n((?:\|.+\|\n?)*)/gm, (_, header, rows) => {
- const hcells = header.split("|").map(c => c.trim()).filter(Boolean);
- const thead = `$1")
.replace(/\*\*([^*]+)\*\*/g, "$1")
@@ -97,33 +78,32 @@ content = content
.replace(/^## (.+)$/gm, "") - .replace(/^(.+)$/gm, (line) => { - if (line.startsWith("<")) return line; - return line; - }); + .replace(/((?:
${line}
`); + } +} +content = wrapped.join("\n"); --- - + -