diff --git a/astro/wiki/src/pages/sl/[...slug].astro b/astro/wiki/src/pages/sl/[...slug].astro new file mode 100644 index 0000000..4a59e6b --- /dev/null +++ b/astro/wiki/src/pages/sl/[...slug].astro @@ -0,0 +1,91 @@ +--- +import fs from "node:fs"; +import path from "node:path"; + +export function getStaticPaths() { + const WIKI_DIR = path.resolve("src/content/sl"); + if (!fs.existsSync(WIKI_DIR)) return []; + const EXCLUDE = [".git", "index.md"]; + function walk(dir, prefix = "") { + const entries = fs.readdirSync(dir, { withFileTypes: true }); + const slugs = []; + for (const e of entries) { + if (e.name.startsWith(".") || EXCLUDE.includes(e.name)) continue; + const full = path.join(dir, e.name); + if (e.isDirectory()) { + slugs.push(...walk(full, prefix ? `${prefix}/${e.name}` : e.name)); + } else if (e.name.endsWith(".md")) { + const rel = prefix ? `${prefix}/${e.name}` : e.name; + slugs.push({ params: { slug: rel.replace(/\.md$/, "") } }); + } + } + return slugs; + } + return walk(WIKI_DIR); +} + +const { slug } = Astro.params; +const WIKI_DIR = path.resolve("src/content/sl"); +const filePath = path.join(WIKI_DIR, `${slug}.md`); + +if (!fs.existsSync(filePath)) { + return new Response("Not found", { status: 404 }); +} + +const raw = fs.readFileSync(filePath, "utf-8"); +let content = raw; +let frontmatter = {}; +if (raw.startsWith("---")) { + const end = raw.indexOf("---", 3); + if (end !== -1) { + for (const line of raw.slice(3, end).split("\n")) { + const m = line.match(/^(\w+):\s*(.+)$/); + if (m) frontmatter[m[1]] = m[2].replace(/^["']|["']$/g, ""); + } + content = raw.slice(end + 3).trim(); + } +} + +const title = (frontmatter.title || slug).replace(/^["']|["']$/g, ""); +content = content.replace(/\]\(\.\/([^)]+)\.md\)/g, "](/sl/$1/)") + .replace(/\]\(\.\.\/([^)]+)\.md\)/g, "](/sl/$1/)") + .replace(/```(\w*)\n([\s\S]*?)```/g, (_, lang, code) => + `
${code.trim()}
`) + .replace(/`([^`]+)`/g, "$1") + .replace(/\*\*([^*]+)\*\*/g, "$1") + .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') + .replace(/^### (.+)$/gm, "

$1

") + .replace(/^## (.+)$/gm, "

$1

") + .replace(/^# (.+)$/gm, "

$1

") + .replace(/^- (.+)$/gm, "
  • $1
  • ") + .replace(/((?:
  • .*<\/li>\n?)+)/g, ""); +const lines = content.split("\n"); +content = lines.map(l => l.startsWith("<") || l === "" ? l : `

    ${l}

    `).join("\n"); +--- + + + + + + {title} — Colibri Wiki + + + + +
    +

    {title}

    + +
    + + diff --git a/astro/wiki/src/pages/sl/index.astro b/astro/wiki/src/pages/sl/index.astro index 99ab775..813a416 100644 --- a/astro/wiki/src/pages/sl/index.astro +++ b/astro/wiki/src/pages/sl/index.astro @@ -2,10 +2,14 @@ import fs from "node:fs"; import path from "node:path"; -const WIKI_DIR = path.resolve("../../../docs/wiki"); +const WIKI_DIR = path.resolve("src/content/sl"); +if (!fs.existsSync(WIKI_DIR)) { + // SL content not staged — return empty page +} const EXCLUDE = [".git", "index.md"]; function walkMarkdown(dir, prefix = "") { + if (!fs.existsSync(dir)) return []; const entries = fs.readdirSync(dir, { withFileTypes: true }); const files = []; for (const e of entries) { @@ -17,10 +21,8 @@ function walkMarkdown(dir, prefix = "") { const rel = prefix ? `${prefix}/${e.name}` : e.name; const slug = rel.replace(/\.md$/, ""); const raw = fs.readFileSync(full, "utf-8"); - const title = raw.match(/^#\s+(.+)$/m)?.[1] || slug; - if (rel.startsWith("sl/")) { - files.push({ slug: slug.replace(/^sl\//, ""), title, file: rel }); - } + const title = raw.match(/^title:\s*"?(.+)"?$/m)?.[1] || raw.match(/^#\s+(.+)$/m)?.[1] || slug; + files.push({ slug, title: title.replace(/^["']|["']$/g, "") }); } } return files.sort((a, b) => a.title.localeCompare(b.title)); @@ -33,28 +35,21 @@ const pages = walkMarkdown(WIKI_DIR); - Colibri Wiki + Colibri Wiki — slovenščina

    Colibri Wiki

    -

    - Strani z odločitvami — zakaj je arhitektura takšna, kot je. - Vzorec LLM Wiki. -

    -

    ← English

    +

    Strani z odločitvami — zakaj za arhitekturo.

    +

    English →