The /kb/ Browser — Markdown to UI Pipeline

Status: Active
Last Updated: 2026-08-26
Category: fogserv - Project Reference
Prerequisites: architecture-overview, ../frontend/tanstack.md
Time: 20 min read
Tags: fogserv, kb, markdown, vite-glob, react-markdown, prerendering, tanstack-router

Summary

How the knowledge base you're reading gets into fogserv.cloud: src/routes/kb_.$.tsx glob-imports every file under /kb/**/*.md as raw strings at build time via Vite's import.meta.glob, parses frontmatter with a small regex parser, and renders articles with react-markdown + GFM. Directory slugs map to README files. No database, no runtime file reads.

Context / Why This Matters

Editing a KB article changes what the website serves only after an image rebuild (deployment-runbook). Understanding this pipeline explains why: the KB is compile-time content, not CMS content. It also matters for authoring — certain frontmatter keys drive the index page, and link style inside articles affects rendering.

Implementation / Core Content

Pipeline stages

kb/**/*.md ──import.meta.glob(?raw)──► slugToContent map ──react-markdown──► /kb/<path> pages
   (repo)         (build time)          (module scope)         (render time)
  1. Glob import (kb_.$.tsx, module scope):

    const mdFiles = import.meta.glob('/kb/**/*.md', { eager: true, query: '?raw' })
    

    eager inlines every article into the bundle; nothing is fetched at request time.

  2. Slug map construction: paths like /kb/networking/wireguard-setup.md become slugs networking/wireguard-setup. A file named readme.md (any case) additionally registers its parent-directory slug, so /kb/networking/ renders networking/README.md.

  3. Frontmatter parsing: regex over the leading --- block into { title?, description?, ... }. The KB index (kb.index.tsx) lists articles from these fields — keep title accurate; it's what readers see before clicking.

  4. Rendering: frontmatter stripped (cleanBody), body passed to ReactMarkdown + remark-gfm.

Authoring implications

Route anatomy

Practical Examples

Publish this article's changes: edit files under kb/, then git push → CI builds image → deploy workflow ships it → verify https://fogserv.cloud/kb/fogserv/kb-browser.

Check a slug locally: run bun run build; Vite logs or a quick node REPL against dist/ output confirm which slugs registered. A 404 at /kb/x/y almost always means filename/slug mismatch (case sensitivity counts).

Common Pitfalls & Troubleshooting

Next Steps / Ops Actions

Sources & Related Articles

Change Log

2026-08-26

Choose Theme

Your selection is saved locally.

Neural Cacophony
Aperture v2
Flux v1
Mosaic Chaos
Nexus v1
Nexus Zest
Prism v2
Synapse