Skip to content

feat(docs): add doc-model types and helpers - #52

Open
mikhd wants to merge 2 commits into
mainfrom
feat/1-doc-model-types
Open

feat(docs): add doc-model types and helpers#52
mikhd wants to merge 2 commits into
mainfrom
feat/1-doc-model-types

Conversation

@mikhd

@mikhd mikhd commented Jul 15, 2026

Copy link
Copy Markdown

[1] Add the full public type contract for the generator (DocModel / DocPage / DocRef / DocConfig, etc.) plus the small ref/name helpers everything downstream reuses.

Further folder structure:

  src/docs/
  ├── index.ts              Public barrel - exports
  ├── types.ts              All doc types (DocConfig, DocRef, DocPage, DocModel, PathConfig, etc.)
  ├── generateDocs.ts       Entry point - orchestrates registry -> render -> model
  ├── navigation.ts         buildNavRegistry (path assignment) + categoryGroups
  ├── ref.ts                DocRef name helpers (refName, displayName, pascalCase, docRefKey)
  ├── links.ts              Links for hrefs
  └── render/
      ├── index.ts          Barrel for render layer
      ├── markdown.ts        markdownRenderer for primitives - MarkupRenderer implementation
      ├── renderType.ts      TypeExpr + helpers (linkedEntity, isDocChild, referencesEnumeration)
      ├── constants.ts      consts
      └── renderPages.ts     Per-page-kind renderers + RenderCtx (node/union/nestedUnion/enum/categoryIndex/rootIndex)

High level overview

  generateDocs(spec, config) runs in three passes.

  Spec  +  DocConfig ({ pathConfig, linkStrategy, root?, inject? })
    │
    ▼
  1) Build "path" registry for all entities buildNavRegistry(spec, config.pathConfig) [navigation.ts]
    │   Walks every category -> categoryGroups() -> assigns pathSegments to each DocRef. 
    │
    ▼
     link(from, to) = config.linkStrategy(registry.lookup(from), registry.lookup(to))
     │   Registry + strategy -> concrete href fn.
     │   Assembled into RenderCtx = { markup: markdownRenderer, registry, config, link }
     │
    ▼
  2) Render phase (loop over spec.categories) [render/renderPages.ts]
    │   For each entity -> renderNodePage / renderUnionPage / renderNestedUnionPage
    │   / renderEnumPage + each category index page.
    │
    │   Each renderer:
    │     - builds its own DocRef + linkTo = link(ref, target)
    │     - assembles page parts (heading, paragraph, tables/lists, inject slots)
    │     - types resolved via renderType() -> markdown blocks via ctx.markup (MarkupRenderer)
    │     - inject?.() hook can fill 'afterDescription' / 'end' slots with custom markup
    │     - returns DocPage { ref, pathSegments (from registry), content }
    │
    ▼
  ③ buildNavigation(spec, pathConfig)  [navigation.ts]
    │   NavCategory[] with grouped, alphabetically-sorted page refs.
    │
    ▼
  Output DocModel { pages: DocPage[] }

Design note:

Before current implementation we considered a fully format-agnostic doc model where every page is a tree of Block (heading, prose, code, table, list) and Inline (text, ref, pageLink, type) nodes with no knowledge of Markdown, links, or escaping. Then swappable renderer layer would walk that tree and do rendering to specific format (md,html,etc)

This was rejected due to its unnecessary complexity and since we only need md format.

@mikhd mikhd changed the title feat(docs): add doc-model types and ref helpers feat(docs): add doc-model types and helpers Jul 15, 2026
@mikhd
mikhd marked this pull request as ready for review July 15, 2026 11:29
@mikhd
mikhd requested a review from lorisleiva July 16, 2026 06:56
@mikhd
mikhd force-pushed the feat/1-doc-model-types branch from 031428e to f85956e Compare July 24, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant