@takazudo/zudo-doc 0.2.21 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/gen-z-index.mjs +164 -0
- package/bin/tags-audit-runner.ts +126 -0
- package/bin/tags-audit.mjs +64 -0
- package/bin/zudo-doc.mjs +83 -0
- package/dist/ai-chat-modal/index.d.ts +8 -0
- package/dist/ai-chat-modal/index.js +243 -0
- package/dist/body-foot-util/body-foot-util-area.d.ts +4 -8
- package/dist/body-foot-util/edit-link.d.ts +4 -8
- package/dist/body-foot-util/index.d.ts +4 -3
- package/dist/breadcrumb/breadcrumb.d.ts +5 -9
- package/dist/breadcrumb/find-path.d.ts +2 -5
- package/dist/breadcrumb/index.d.ts +4 -4
- package/dist/breadcrumb/types.d.ts +3 -5
- package/dist/category-nav/index.d.ts +86 -0
- package/dist/category-nav/index.js +44 -0
- package/dist/category-tree-nav/index.d.ts +65 -0
- package/dist/category-tree-nav/index.js +24 -0
- package/dist/code-group/index.d.ts +10 -0
- package/dist/code-group/index.js +37 -0
- package/dist/code-syntax/code-block-enhancer-script.d.ts +1 -3
- package/dist/code-syntax/code-block-enhancer.d.ts +3 -6
- package/dist/code-syntax/index.d.ts +9 -8
- package/dist/code-syntax/mermaid-init-script.d.ts +3 -5
- package/dist/code-syntax/mermaid-init.d.ts +4 -7
- package/dist/code-syntax/tabs-init-script.d.ts +1 -3
- package/dist/code-syntax/tabs-init.d.ts +3 -6
- package/dist/code-syntax/tabs.d.ts +4 -7
- package/dist/color-scheme-utils.d.ts +125 -0
- package/dist/color-scheme-utils.js +151 -0
- package/dist/compose-meta-title/index.d.ts +7 -0
- package/dist/compose-meta-title/index.js +10 -0
- package/dist/content/component-map.d.ts +13 -17
- package/dist/content/content-blockquote.d.ts +3 -6
- package/dist/content/content-code.d.ts +3 -6
- package/dist/content/content-code.js +1 -1
- package/dist/content/content-link.d.ts +3 -6
- package/dist/content/content-link.js +1 -1
- package/dist/content/content-ol.d.ts +3 -6
- package/dist/content/content-paragraph.d.ts +3 -6
- package/dist/content/content-strong.d.ts +3 -6
- package/dist/content/content-table.d.ts +3 -6
- package/dist/content/content-ul.d.ts +3 -6
- package/dist/content/heading-h2.d.ts +3 -6
- package/dist/content/heading-h3.d.ts +3 -6
- package/dist/content/heading-h4.d.ts +3 -6
- package/dist/content/index.d.ts +29 -13
- package/dist/content-admonition/index.d.ts +15 -0
- package/dist/content-admonition/index.js +14 -0
- package/dist/design-token-panel-bootstrap.d.ts +38 -0
- package/dist/design-token-panel-bootstrap.js +29 -0
- package/dist/desktop-sidebar-toggle-island/index.d.ts +5 -0
- package/dist/desktop-sidebar-toggle-island/index.js +62 -0
- package/dist/details/details.d.ts +3 -7
- package/dist/details/index.d.ts +2 -2
- package/dist/doc-body-end/index.d.ts +21 -0
- package/dist/doc-body-end/index.js +15 -0
- package/dist/doc-content-header/index.d.ts +69 -0
- package/dist/doc-content-header/index.js +49 -0
- package/dist/doc-history/index.d.ts +10 -0
- package/dist/doc-history/index.js +407 -0
- package/dist/doc-history-area/index.d.ts +84 -0
- package/dist/doc-history-area/index.js +76 -0
- package/dist/doc-metainfo-area/index.d.ts +46 -0
- package/dist/doc-metainfo-area/index.js +41 -0
- package/dist/doc-page-props/index.d.ts +93 -0
- package/dist/doc-page-props/index.js +0 -0
- package/dist/doc-page-renderer/index.d.ts +128 -0
- package/dist/doc-page-renderer/index.js +103 -0
- package/dist/doc-page-shell/index.d.ts +136 -0
- package/dist/doc-page-shell/index.js +127 -0
- package/dist/doc-pager/index.d.ts +25 -0
- package/dist/doc-pager/index.js +41 -0
- package/dist/doc-route-entries/index.d.ts +125 -0
- package/dist/doc-route-entries/index.js +76 -0
- package/dist/doc-route-paths/index.d.ts +54 -0
- package/dist/doc-route-paths/index.js +61 -0
- package/dist/doc-tags-area/index.d.ts +38 -0
- package/dist/doc-tags-area/index.js +30 -0
- package/dist/doclayout/anchors.d.ts +7 -9
- package/dist/doclayout/doc-layout-with-defaults.d.ts +16 -12
- package/dist/doclayout/doc-layout.d.ts +5 -9
- package/dist/doclayout/index.d.ts +6 -6
- package/dist/eject/index.d.ts +33 -0
- package/dist/eject/index.js +229 -0
- package/dist/extract-headings/index.d.ts +43 -0
- package/dist/extract-headings/index.js +111 -0
- package/dist/factory-context/index.d.ts +80 -0
- package/dist/factory-context/index.js +0 -0
- package/dist/features.css +882 -0
- package/dist/footer/footer.d.ts +4 -8
- package/dist/footer/index.d.ts +13 -3
- package/dist/footer/types.d.ts +4 -6
- package/dist/footer-with-defaults/index.d.ts +63 -0
- package/dist/footer-with-defaults/index.js +128 -0
- package/dist/frontmatter-preview-data/index.d.ts +26 -0
- package/dist/frontmatter-preview-data/index.js +23 -0
- package/dist/github-helpers/index.d.ts +17 -0
- package/dist/github-helpers/index.js +16 -0
- package/dist/head/doc-head.d.ts +3 -6
- package/dist/head/index.d.ts +9 -5
- package/dist/head/og-tags.d.ts +4 -7
- package/dist/head/twitter-card.d.ts +3 -6
- package/dist/head/types.d.ts +1 -3
- package/dist/head-with-defaults/index.d.ts +49 -0
- package/dist/head-with-defaults/index.js +62 -0
- package/dist/header/header.d.ts +6 -10
- package/dist/header/index.d.ts +16 -6
- package/dist/header/nav-active.d.ts +5 -7
- package/dist/header/nav-overflow-script.d.ts +1 -3
- package/dist/header/right-items.d.ts +3 -6
- package/dist/header/types.d.ts +10 -12
- package/dist/header-with-defaults/index.d.ts +77 -0
- package/dist/header-with-defaults/index.js +163 -0
- package/dist/html-preview-wrapper/dedent.d.ts +1 -3
- package/dist/html-preview-wrapper/highlighted-code.d.ts +3 -7
- package/dist/html-preview-wrapper/html-preview-wrapper.d.ts +6 -10
- package/dist/html-preview-wrapper/html-preview.d.ts +5 -9
- package/dist/html-preview-wrapper/index.d.ts +8 -5
- package/dist/html-preview-wrapper/preflight.d.ts +1 -3
- package/dist/html-preview-wrapper/preview-base.d.ts +4 -8
- package/dist/i18n-version/index.d.ts +7 -5
- package/dist/i18n-version/language-switcher.d.ts +5 -8
- package/dist/i18n-version/types.d.ts +3 -5
- package/dist/i18n-version/version-banner.d.ts +4 -8
- package/dist/i18n-version/version-switcher.d.ts +7 -10
- package/dist/icons/index.d.ts +9 -13
- package/dist/image-enlarge/index.d.ts +13 -0
- package/dist/image-enlarge/index.js +176 -0
- package/dist/index.d.ts +26 -2
- package/dist/inline-version-switcher/index.d.ts +31 -0
- package/dist/inline-version-switcher/index.js +44 -0
- package/dist/integrations/claude-resources/escape-for-mdx.d.ts +1 -3
- package/dist/integrations/claude-resources/generate.d.ts +2 -4
- package/dist/integrations/claude-resources/index.d.ts +7 -10
- package/dist/integrations/doc-history/index.d.ts +21 -24
- package/dist/integrations/doc-history/pre-build.d.ts +7 -9
- package/dist/integrations/llms-txt/dev-middleware.d.ts +7 -11
- package/dist/integrations/llms-txt/emit.d.ts +2 -7
- package/dist/integrations/llms-txt/generate.d.ts +3 -8
- package/dist/integrations/llms-txt/index.d.ts +33 -8
- package/dist/integrations/llms-txt/load.d.ts +3 -7
- package/dist/integrations/llms-txt/strip.d.ts +2 -6
- package/dist/integrations/llms-txt/types.d.ts +9 -13
- package/dist/integrations/search-index/build-emitter.d.ts +4 -7
- package/dist/integrations/search-index/collect.d.ts +2 -5
- package/dist/integrations/search-index/dev-middleware.d.ts +5 -8
- package/dist/integrations/search-index/index.d.ts +7 -5
- package/dist/integrations/search-index/types.d.ts +5 -7
- package/dist/island-types/index.d.ts +44 -0
- package/dist/island-types/index.js +12 -0
- package/dist/locale-merge/index.d.ts +114 -0
- package/dist/locale-merge/index.js +27 -0
- package/dist/math-block/index.d.ts +18 -0
- package/dist/math-block/index.js +29 -0
- package/dist/md-utils/index.d.ts +6 -8
- package/dist/md-utils/index.js +2 -1
- package/dist/mdx-components/index.d.ts +46 -0
- package/dist/mdx-components/index.js +161 -0
- package/dist/mermaid-enlarge/index.d.ts +11 -0
- package/dist/mermaid-enlarge/index.js +290 -0
- package/dist/metainfo/doc-metainfo.d.ts +5 -9
- package/dist/metainfo/doc-tags.d.ts +7 -11
- package/dist/metainfo/frontmatter-preview.d.ts +8 -12
- package/dist/metainfo/index.d.ts +6 -4
- package/dist/nav-data-prep/index.d.ts +72 -0
- package/dist/nav-data-prep/index.js +34 -0
- package/dist/nav-indexing/category-nav.d.ts +4 -8
- package/dist/nav-indexing/category-tree-nav.d.ts +4 -8
- package/dist/nav-indexing/doc-card-grid.d.ts +4 -8
- package/dist/nav-indexing/docs-sitemap.d.ts +4 -8
- package/dist/nav-indexing/index.d.ts +37 -10
- package/dist/nav-indexing/nav-card-grid.d.ts +4 -8
- package/dist/nav-indexing/site-tree-nav-demo.d.ts +4 -8
- package/dist/nav-indexing/tag-nav.d.ts +6 -10
- package/dist/nav-indexing/types.d.ts +6 -8
- package/dist/nav-indexing/versions-page-content.d.ts +4 -8
- package/dist/nav-scope/index.d.ts +41 -0
- package/dist/nav-scope/index.js +41 -0
- package/dist/nav-source-cache/index.d.ts +13 -0
- package/dist/nav-source-cache/index.js +28 -0
- package/dist/nav-source-docs/index.d.ts +169 -0
- package/dist/nav-source-docs/index.js +123 -0
- package/dist/page-loading/index.d.ts +1 -2
- package/dist/page-loading/page-loading-overlay.d.ts +4 -8
- package/dist/plugins/claude-resources.d.ts +3 -0
- package/dist/plugins/claude-resources.js +27 -0
- package/dist/plugins/connect-adapter.d.ts +31 -0
- package/dist/plugins/connect-adapter.js +78 -0
- package/dist/plugins/doc-history.d.ts +3 -0
- package/dist/plugins/doc-history.js +54 -0
- package/dist/plugins/llms-txt.d.ts +3 -0
- package/dist/plugins/llms-txt.js +48 -0
- package/dist/plugins/plugin-utils.d.ts +17 -0
- package/dist/plugins/plugin-utils.js +11 -0
- package/dist/plugins/routes.d.ts +2 -0
- package/dist/plugins/routes.js +100 -0
- package/dist/plugins/search-index.d.ts +3 -0
- package/dist/plugins/search-index.js +24 -0
- package/dist/preset.d.ts +198 -0
- package/dist/preset.js +185 -0
- package/dist/render-markdown/index.d.ts +5 -0
- package/dist/render-markdown/index.js +115 -0
- package/dist/robots.d.ts +36 -0
- package/dist/robots.js +17 -0
- package/dist/route-enumerators/index.d.ts +204 -0
- package/dist/route-enumerators/index.js +156 -0
- package/dist/routes/404.d.ts +7 -0
- package/dist/routes/404.js +47 -0
- package/dist/routes/_chrome.d.ts +32 -0
- package/dist/routes/_chrome.js +365 -0
- package/dist/routes/_context.d.ts +56 -0
- package/dist/routes/_context.js +222 -0
- package/dist/routes/_docs-helpers.d.ts +43 -0
- package/dist/routes/_docs-helpers.js +173 -0
- package/dist/routes/_virtual.d.js +0 -0
- package/dist/routes/api-ai-chat.d.ts +5 -0
- package/dist/routes/api-ai-chat.js +24 -0
- package/dist/routes/docs-slug.d.ts +21 -0
- package/dist/routes/docs-slug.js +26 -0
- package/dist/routes/docs-tags-index.d.ts +7 -0
- package/dist/routes/docs-tags-index.js +11 -0
- package/dist/routes/docs-tags-tag.d.ts +23 -0
- package/dist/routes/docs-tags-tag.js +19 -0
- package/dist/routes/docs-versions.d.ts +7 -0
- package/dist/routes/docs-versions.js +11 -0
- package/dist/routes/index.d.ts +7 -0
- package/dist/routes/index.js +117 -0
- package/dist/routes/locale-docs-slug.d.ts +27 -0
- package/dist/routes/locale-docs-slug.js +40 -0
- package/dist/routes/locale-docs-tags-index.d.ts +18 -0
- package/dist/routes/locale-docs-tags-index.js +15 -0
- package/dist/routes/locale-docs-tags-tag.d.ts +25 -0
- package/dist/routes/locale-docs-tags-tag.js +22 -0
- package/dist/routes/locale-docs-versions.d.ts +18 -0
- package/dist/routes/locale-docs-versions.js +15 -0
- package/dist/routes/locale-index.d.ts +24 -0
- package/dist/routes/locale-index.js +132 -0
- package/dist/routes/robots.txt.d.ts +3 -0
- package/dist/routes/robots.txt.js +8 -0
- package/dist/routes/sitemap.xml.d.ts +5 -0
- package/dist/routes/sitemap.xml.js +31 -0
- package/dist/routes/v-docs-slug.d.ts +27 -0
- package/dist/routes/v-docs-slug.js +34 -0
- package/dist/routes/v-locale-docs-slug.d.ts +31 -0
- package/dist/routes/v-locale-docs-slug.js +50 -0
- package/dist/safelist.css +1 -1
- package/dist/search-widget/index.d.ts +38 -0
- package/dist/search-widget/index.js +169 -0
- package/dist/search-widget-script/index.d.ts +18 -0
- package/dist/search-widget-script/index.js +465 -0
- package/dist/settings.d.ts +270 -0
- package/dist/settings.js +0 -0
- package/dist/sidebar/index.d.ts +21 -3
- package/dist/sidebar/sidebar.d.ts +5 -9
- package/dist/sidebar/types.d.ts +4 -6
- package/dist/sidebar-prepaint/index.d.ts +21 -0
- package/dist/sidebar-prepaint/index.js +23 -0
- package/dist/sidebar-resizer/index.d.ts +2 -6
- package/dist/sidebar-resizer/sidebar-resizer-init.d.ts +6 -10
- package/dist/sidebar-toggle-island/index.d.ts +13 -0
- package/dist/sidebar-toggle-island/index.js +122 -0
- package/dist/sidebar-tree/build-tree.d.ts +4 -8
- package/dist/sidebar-tree/category-meta.d.ts +3 -6
- package/dist/sidebar-tree/index.d.ts +18 -3
- package/dist/sidebar-tree/types.d.ts +6 -8
- package/dist/sidebar-tree-island/index.d.ts +13 -0
- package/dist/sidebar-tree-island/index.js +454 -0
- package/dist/sidebar-utils/index.d.ts +64 -0
- package/dist/sidebar-utils/index.js +88 -0
- package/dist/sidebar-with-defaults/index.d.ts +38 -0
- package/dist/sidebar-with-defaults/index.js +45 -0
- package/dist/site-tree-nav/index.d.ts +71 -0
- package/dist/site-tree-nav/index.js +36 -0
- package/dist/site-tree-nav-island/index.d.ts +11 -0
- package/dist/site-tree-nav-island/index.js +176 -0
- package/dist/slug/index.d.ts +4 -0
- package/dist/slug/index.js +19 -0
- package/dist/smart-break/index.d.ts +55 -0
- package/dist/{toc/smart-break.js → smart-break/index.js} +30 -3
- package/dist/tab-item/index.d.ts +2 -2
- package/dist/tab-item/tab-item.d.ts +6 -7
- package/dist/tag-helpers/index.d.ts +40 -0
- package/dist/tag-helpers/index.js +54 -0
- package/dist/tag-pages/index.d.ts +114 -0
- package/dist/tag-pages/index.js +146 -0
- package/dist/tags-audit.d.ts +107 -0
- package/dist/tags-audit.js +321 -0
- package/dist/theme/color-scheme-provider.d.ts +4 -8
- package/dist/theme/color-tweak-export-modal.d.ts +4 -7
- package/dist/theme/design-token-serde.d.ts +14 -17
- package/dist/theme/design-token-types.d.ts +4 -6
- package/dist/theme/iframe-bridge.d.ts +12 -14
- package/dist/theme/index.d.ts +7 -9
- package/dist/theme/theme-toggle.d.ts +3 -8
- package/dist/theme-toggle/color-scheme-sync.d.ts +5 -7
- package/dist/theme-toggle/index.d.ts +4 -8
- package/dist/toc/cx.d.ts +2 -3
- package/dist/toc/index.d.ts +8 -6
- package/dist/toc/mobile-toc.d.ts +5 -9
- package/dist/toc/mobile-toc.js +1 -1
- package/dist/toc/toc-title.d.ts +1 -3
- package/dist/toc/toc.d.ts +5 -9
- package/dist/toc/toc.js +1 -1
- package/dist/toc/types.d.ts +1 -3
- package/dist/toc/use-active-heading.d.ts +4 -7
- package/dist/transitions/index.d.ts +1 -1
- package/dist/transitions/page-events.d.ts +4 -6
- package/dist/tree-nav-shared/index.d.ts +22 -0
- package/dist/tree-nav-shared/index.js +66 -0
- package/dist/url-helpers/index.d.ts +37 -0
- package/dist/url-helpers/index.js +106 -0
- package/dist/url-normalizer/index.d.ts +39 -1
- package/dist/url-normalizer/normalize.d.ts +3 -5
- package/dist/use-modal-dialog/index.d.ts +70 -0
- package/dist/use-modal-dialog/index.js +73 -0
- package/dist/versions-page/index.d.ts +55 -0
- package/dist/versions-page/index.js +73 -0
- package/eject/breadcrumb/breadcrumb.tsx +194 -0
- package/eject/breadcrumb/find-path.ts +26 -0
- package/eject/breadcrumb/index.ts +4 -0
- package/eject/breadcrumb/types.ts +32 -0
- package/eject/code-group/index.tsx +78 -0
- package/eject/content-admonition/index.tsx +50 -0
- package/eject/details/details.tsx +34 -0
- package/eject/details/index.ts +4 -0
- package/eject/doc-pager/index.tsx +91 -0
- package/eject/footer/footer.tsx +167 -0
- package/eject/footer/index.ts +19 -0
- package/eject/footer/types.ts +60 -0
- package/eject/header/header.tsx +725 -0
- package/eject/header/index.ts +36 -0
- package/eject/header/nav-active.ts +122 -0
- package/eject/header/nav-overflow-script.ts +302 -0
- package/eject/header/right-items.ts +78 -0
- package/eject/header/types.ts +69 -0
- package/eject/page-loading/index.ts +10 -0
- package/eject/page-loading/page-loading-overlay.tsx +103 -0
- package/eject/sidebar/index.ts +27 -0
- package/eject/sidebar/sidebar.tsx +137 -0
- package/eject/sidebar/types.ts +73 -0
- package/eject/tab-item/index.ts +7 -0
- package/eject/tab-item/tab-item.tsx +70 -0
- package/eject/theme-toggle/color-scheme-sync.ts +73 -0
- package/eject/theme-toggle/index.tsx +120 -0
- package/eject/toc/cx.ts +38 -0
- package/eject/toc/index.ts +11 -0
- package/eject/toc/mobile-toc.tsx +133 -0
- package/eject/toc/toc-title.ts +33 -0
- package/eject/toc/toc.tsx +119 -0
- package/eject/toc/types.ts +14 -0
- package/eject/toc/use-active-heading.ts +162 -0
- package/package.json +371 -11
- package/routes-src/404.tsx +49 -0
- package/routes-src/_chrome.tsx +470 -0
- package/routes-src/_context.ts +314 -0
- package/routes-src/_docs-helpers.ts +284 -0
- package/routes-src/_virtual.d.ts +15 -0
- package/routes-src/api-ai-chat.tsx +46 -0
- package/routes-src/docs-slug.tsx +43 -0
- package/routes-src/docs-tags-index.tsx +14 -0
- package/routes-src/docs-tags-tag.tsx +29 -0
- package/routes-src/docs-versions.tsx +15 -0
- package/routes-src/index.tsx +134 -0
- package/routes-src/locale-docs-slug.tsx +69 -0
- package/routes-src/locale-docs-tags-index.tsx +23 -0
- package/routes-src/locale-docs-tags-tag.tsx +39 -0
- package/routes-src/locale-docs-versions.tsx +23 -0
- package/routes-src/locale-index.tsx +150 -0
- package/routes-src/robots.txt.tsx +13 -0
- package/routes-src/sitemap.xml.tsx +48 -0
- package/routes-src/v-docs-slug.tsx +64 -0
- package/routes-src/v-locale-docs-slug.tsx +85 -0
- package/dist/toc/smart-break.d.ts +0 -27
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@takazudo/zudo-doc/preset` — the package-first config preset.
|
|
3
|
+
*
|
|
4
|
+
* `zudoDocPreset()` returns the zfb config fragment that every zudo-doc
|
|
5
|
+
* project previously hand-wrote in its `zfb.config.ts` (collections loop,
|
|
6
|
+
* markdown.features, dual-theme codeHighlight, resolveMarkdownLinks,
|
|
7
|
+
* stripMdExt, trailingSlash, and the integration plugins array). The host
|
|
8
|
+
* config spreads this fragment into `defineConfig` and supplies only the
|
|
9
|
+
* project-specific shell fields it still owns (`framework`, `port`,
|
|
10
|
+
* `tailwind`, `bundle`, `base`, `adapter`).
|
|
11
|
+
*
|
|
12
|
+
* ──────────────────────────────────────────────────────────────────────────
|
|
13
|
+
* NODE-BUILTIN-FREE EVAL GRAPH (non-negotiable — guarded by a unit test)
|
|
14
|
+
* ──────────────────────────────────────────────────────────────────────────
|
|
15
|
+
* zfb evaluates the config module through esbuild with `--platform=neutral`
|
|
16
|
+
* (mirrors zfb's `loader.rs:277`); a transitive `node:*` import fails the
|
|
17
|
+
* load. This preset is the central node in that eval graph, so it MUST stay
|
|
18
|
+
* free of `node:*` builtins:
|
|
19
|
+
*
|
|
20
|
+
* - The signature takes `buildDocsSchema` and `directiveVocabulary` as
|
|
21
|
+
* INPUTS rather than importing the project's `src/config/*` singletons.
|
|
22
|
+
* Those singletons (`settings`, `tag-vocabulary`, `docs-schema`) are
|
|
23
|
+
* already pulled into the config eval at the call site; re-importing them
|
|
24
|
+
* here would (a) double-import the singletons and (b) risk dragging a
|
|
25
|
+
* `node:*` dependency into this module's own import graph.
|
|
26
|
+
* - Plugins are emitted as **bare-specifier descriptors**
|
|
27
|
+
* (`{ name: "@takazudo/zudo-doc/plugins/<x>", options }`), NEVER imported
|
|
28
|
+
* plugin functions. zfb's plugin runtime loads each `name` as a module
|
|
29
|
+
* specifier and dispatches lifecycle hooks against it; importing the
|
|
30
|
+
* plugin modules here would pull their `node:fs` / `node:path` graph into
|
|
31
|
+
* the config eval.
|
|
32
|
+
* - The only runtime dependency is `zod` (for `z.toJSONSchema`), which
|
|
33
|
+
* bundles cleanly under `--platform=neutral` (verified: zero `node:*`).
|
|
34
|
+
*/
|
|
35
|
+
import { z } from "zod";
|
|
36
|
+
/** A single locale's content directory (`settings.locales[code]`). */
|
|
37
|
+
export interface PresetLocaleConfig {
|
|
38
|
+
dir: string;
|
|
39
|
+
}
|
|
40
|
+
/** A single docs version (`settings.versions[n]`). */
|
|
41
|
+
export interface PresetVersionConfig {
|
|
42
|
+
slug: string;
|
|
43
|
+
docsDir: string;
|
|
44
|
+
locales?: Record<string, {
|
|
45
|
+
dir: string;
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
48
|
+
/** The `settings.claudeResources` block (or `false` when disabled). */
|
|
49
|
+
export interface PresetClaudeResourcesConfig {
|
|
50
|
+
claudeDir: string;
|
|
51
|
+
projectRoot?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The subset of `settings` the preset reads. Any concrete `typeof settings`
|
|
55
|
+
* (this repo's or a generated project's) is assignable to this — the preset
|
|
56
|
+
* only consumes these fields.
|
|
57
|
+
*/
|
|
58
|
+
export interface PresetSettings {
|
|
59
|
+
docsDir: string;
|
|
60
|
+
locales: Record<string, PresetLocaleConfig>;
|
|
61
|
+
versions?: PresetVersionConfig[] | false;
|
|
62
|
+
base: string;
|
|
63
|
+
siteName: string;
|
|
64
|
+
siteDescription: string;
|
|
65
|
+
siteUrl: string;
|
|
66
|
+
trailingSlash: boolean;
|
|
67
|
+
mermaid: boolean;
|
|
68
|
+
onBrokenMarkdownLinks: "warn" | "error" | "ignore";
|
|
69
|
+
headingIdStrategy: "flat" | "hierarchical";
|
|
70
|
+
llmsTxt?: boolean;
|
|
71
|
+
docHistory?: boolean;
|
|
72
|
+
claudeResources?: PresetClaudeResourcesConfig | false;
|
|
73
|
+
/** "owner/repo" — when set, enables `#123` / SHA autolinks in markdown. Omit to disable entirely. */
|
|
74
|
+
githubAutolinksRepo?: string;
|
|
75
|
+
/** When `true`, the preset adds the package-owned route-injection plugin
|
|
76
|
+
* (`@takazudo/zudo-doc/plugins/routes`). On by default since the fast-follow
|
|
77
|
+
* (#2372): the showcase and create-zudo-doc both EMIT `packageOwnedRoutes: true`
|
|
78
|
+
* into their generated `settings.ts`. `buildPlugins` reads this value truthily
|
|
79
|
+
* and does NO central defaulting — a hand-written settings object that OMITS the
|
|
80
|
+
* field is treated as off; set it explicitly to control injection.
|
|
81
|
+
* See `docs/adr/route-injection-seam.md`. */
|
|
82
|
+
packageOwnedRoutes?: boolean;
|
|
83
|
+
/** Gate for the `/docs/tags` + `/docs/tags/[tag]` injected routes. */
|
|
84
|
+
docTags?: boolean;
|
|
85
|
+
/** Gate for the SSR `/api/ai-chat` injected route (`prerender: false`). */
|
|
86
|
+
aiAssistant?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The directives recipe map (`markdown.features.directives`): directive name →
|
|
90
|
+
* the JSX component name it resolves to (registered in the host's
|
|
91
|
+
* `pages/_mdx-components.ts`). Passed in rather than hardcoded so a project can
|
|
92
|
+
* register its own directives without editing the preset; the showcase passes
|
|
93
|
+
* the canonical seven (note/tip/info/warning/danger/caution/details).
|
|
94
|
+
*/
|
|
95
|
+
export type DirectiveVocabulary = Record<string, string>;
|
|
96
|
+
/**
|
|
97
|
+
* The UI-string translation table (`src/config/i18n.ts` `translations`).
|
|
98
|
+
* Locale code → key → translated string. Passed (not imported) so the preset's
|
|
99
|
+
* import graph stays node-builtin-free; rides into the route-context virtual
|
|
100
|
+
* module verbatim when `packageOwnedRoutes` is on. Optional — only consumed by
|
|
101
|
+
* the routes plugin; omitting it makes the virtual module carry `{}`.
|
|
102
|
+
*/
|
|
103
|
+
export type PresetTranslations = Record<string, Record<string, string>>;
|
|
104
|
+
/**
|
|
105
|
+
* The tag vocabulary entries (`src/config/tag-vocabulary.ts`). Serializable
|
|
106
|
+
* data, threaded into the route-context virtual module when
|
|
107
|
+
* `packageOwnedRoutes` is on. Optional — only consumed by the routes plugin.
|
|
108
|
+
*/
|
|
109
|
+
export type PresetTagVocabularyEntry = {
|
|
110
|
+
id: string;
|
|
111
|
+
label?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
group?: string;
|
|
114
|
+
aliases?: readonly string[];
|
|
115
|
+
deprecated?: boolean | {
|
|
116
|
+
redirect?: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/** Arguments to `zudoDocPreset`. */
|
|
120
|
+
export interface ZudoDocPresetArgs {
|
|
121
|
+
/** The project's `settings` object (structurally `PresetSettings`). */
|
|
122
|
+
settings: PresetSettings;
|
|
123
|
+
/**
|
|
124
|
+
* The project's `buildDocsSchema` — the zod schema builder from
|
|
125
|
+
* `src/config/docs-schema.ts`. Passed (not imported) so the preset never
|
|
126
|
+
* re-imports the project's `settings` / `tag-vocabulary` singletons, keeping
|
|
127
|
+
* this module's import graph node-builtin-free. Called once; the result is
|
|
128
|
+
* converted to JSON Schema and reused for every collection.
|
|
129
|
+
*/
|
|
130
|
+
buildDocsSchema: () => z.ZodType;
|
|
131
|
+
/**
|
|
132
|
+
* The directives recipe map. See {@link DirectiveVocabulary}.
|
|
133
|
+
*/
|
|
134
|
+
directiveVocabulary: DirectiveVocabulary;
|
|
135
|
+
/**
|
|
136
|
+
* The host's UI-string translation table. Only consumed when
|
|
137
|
+
* `settings.packageOwnedRoutes` is true (rides into the route-context virtual
|
|
138
|
+
* module). Optional — defaults to `{}`. See {@link PresetTranslations}.
|
|
139
|
+
*/
|
|
140
|
+
translations?: PresetTranslations;
|
|
141
|
+
/**
|
|
142
|
+
* The host's tag vocabulary entries. Only consumed when
|
|
143
|
+
* `settings.packageOwnedRoutes` is true. Optional — defaults to `[]`.
|
|
144
|
+
*/
|
|
145
|
+
tagVocabulary?: readonly PresetTagVocabularyEntry[];
|
|
146
|
+
}
|
|
147
|
+
export interface PresetCollection {
|
|
148
|
+
name: string;
|
|
149
|
+
path: string;
|
|
150
|
+
schema: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
export interface PresetPlugin {
|
|
153
|
+
name: string;
|
|
154
|
+
options?: Record<string, unknown>;
|
|
155
|
+
}
|
|
156
|
+
export interface PresetResolveMarkdownLinks {
|
|
157
|
+
enabled: boolean;
|
|
158
|
+
dirs: Array<{
|
|
159
|
+
dir: string;
|
|
160
|
+
routePrefix: string;
|
|
161
|
+
}>;
|
|
162
|
+
onBrokenLinks: "warn" | "error" | "ignore";
|
|
163
|
+
}
|
|
164
|
+
export interface PresetMarkdown {
|
|
165
|
+
features: Record<string, boolean | Record<string, unknown>>;
|
|
166
|
+
}
|
|
167
|
+
export interface PresetCodeHighlight {
|
|
168
|
+
themeLight: string;
|
|
169
|
+
themeDark: string;
|
|
170
|
+
}
|
|
171
|
+
/** The config fragment returned by {@link zudoDocPreset}. */
|
|
172
|
+
export interface ZudoDocPresetResult {
|
|
173
|
+
collections: PresetCollection[];
|
|
174
|
+
plugins: PresetPlugin[];
|
|
175
|
+
markdown: PresetMarkdown;
|
|
176
|
+
codeHighlight: PresetCodeHighlight;
|
|
177
|
+
resolveMarkdownLinks: PresetResolveMarkdownLinks;
|
|
178
|
+
stripMdExt: boolean;
|
|
179
|
+
trailingSlash: boolean;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Build the zudo-doc zfb config fragment from project settings.
|
|
183
|
+
*
|
|
184
|
+
* Spread the result into `defineConfig`:
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* export default defineConfig({
|
|
188
|
+
* framework: "preact",
|
|
189
|
+
* port: 4321,
|
|
190
|
+
* tailwind: { enabled: true },
|
|
191
|
+
* bundle: { exclude: [...] },
|
|
192
|
+
* base: settings.base,
|
|
193
|
+
* adapter: "@takazudo/zfb-adapter-cloudflare",
|
|
194
|
+
* ...zudoDocPreset({ settings, buildDocsSchema, directiveVocabulary }),
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function zudoDocPreset({ settings, buildDocsSchema, directiveVocabulary, translations, tagVocabulary, }: ZudoDocPresetArgs): ZudoDocPresetResult;
|
package/dist/preset.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function zudoDocPreset({
|
|
3
|
+
settings,
|
|
4
|
+
buildDocsSchema,
|
|
5
|
+
directiveVocabulary,
|
|
6
|
+
translations,
|
|
7
|
+
tagVocabulary
|
|
8
|
+
}) {
|
|
9
|
+
const docsSchemaJson = z.toJSONSchema(buildDocsSchema());
|
|
10
|
+
return {
|
|
11
|
+
collections: buildCollections(settings, docsSchemaJson),
|
|
12
|
+
plugins: buildPlugins(settings, { translations, tagVocabulary }),
|
|
13
|
+
markdown: { features: buildMarkdownFeatures(settings, directiveVocabulary) },
|
|
14
|
+
// Dual-theme syntect (zfb >= 0.1.0-next.45). Theme names are SYNTECT
|
|
15
|
+
// built-ins, NOT Shiki names. Tokens emit `--shiki-light`/`--shiki-dark`
|
|
16
|
+
// CSS custom properties resolved by the host CSS via `light-dark()`, so
|
|
17
|
+
// code follows the in-page light/dark switch with zero client JS.
|
|
18
|
+
codeHighlight: {
|
|
19
|
+
themeLight: "base16-ocean.light",
|
|
20
|
+
themeDark: "base16-ocean.dark"
|
|
21
|
+
},
|
|
22
|
+
resolveMarkdownLinks: buildResolveMarkdownLinks(settings),
|
|
23
|
+
// Strip `.md` / `.mdx` from in-page `<a href>` so author-written
|
|
24
|
+
// `[label](./other.mdx)` references resolve to the rendered route URL.
|
|
25
|
+
stripMdExt: true,
|
|
26
|
+
trailingSlash: settings.trailingSlash
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function buildCollections(settings, docsSchemaJson) {
|
|
30
|
+
const collections = [];
|
|
31
|
+
collections.push({ name: "docs", path: settings.docsDir, schema: docsSchemaJson });
|
|
32
|
+
for (const [code, config] of Object.entries(settings.locales)) {
|
|
33
|
+
collections.push({ name: `docs-${code}`, path: config.dir, schema: docsSchemaJson });
|
|
34
|
+
}
|
|
35
|
+
if (settings.versions) {
|
|
36
|
+
for (const version of settings.versions) {
|
|
37
|
+
collections.push({
|
|
38
|
+
name: `docs-v-${version.slug}`,
|
|
39
|
+
path: version.docsDir,
|
|
40
|
+
schema: docsSchemaJson
|
|
41
|
+
});
|
|
42
|
+
if (version.locales) {
|
|
43
|
+
for (const [code, config] of Object.entries(version.locales)) {
|
|
44
|
+
collections.push({
|
|
45
|
+
name: `docs-v-${version.slug}-${code}`,
|
|
46
|
+
path: config.dir,
|
|
47
|
+
schema: docsSchemaJson
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return collections;
|
|
54
|
+
}
|
|
55
|
+
function buildResolveMarkdownLinks(settings) {
|
|
56
|
+
return {
|
|
57
|
+
enabled: true,
|
|
58
|
+
dirs: [
|
|
59
|
+
{ dir: settings.docsDir, routePrefix: "/docs/" },
|
|
60
|
+
...Object.entries(settings.locales).map(([code, locale]) => ({
|
|
61
|
+
dir: locale.dir,
|
|
62
|
+
routePrefix: `/${code}/docs/`
|
|
63
|
+
})),
|
|
64
|
+
// Versioned collections: each version's EN dir + per-locale dirs.
|
|
65
|
+
...settings.versions ? settings.versions.flatMap((version) => [
|
|
66
|
+
{ dir: version.docsDir, routePrefix: `/v/${version.slug}/docs/` },
|
|
67
|
+
...Object.entries(version.locales ?? {}).map(([code, locale]) => ({
|
|
68
|
+
dir: locale.dir,
|
|
69
|
+
routePrefix: `/v/${version.slug}/${code}/docs/`
|
|
70
|
+
}))
|
|
71
|
+
]) : []
|
|
72
|
+
],
|
|
73
|
+
onBrokenLinks: settings.onBrokenMarkdownLinks
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function buildMarkdownFeatures(settings, directiveVocabulary) {
|
|
77
|
+
return {
|
|
78
|
+
// Former-Core directives (next.25 generic `directives` map). Keys are
|
|
79
|
+
// directive names, values are the JSX component names they resolve to
|
|
80
|
+
// (registered in the host's pages/_mdx-components.ts).
|
|
81
|
+
directives: { ...directiveVocabulary },
|
|
82
|
+
mermaid: settings.mermaid,
|
|
83
|
+
headingMarkerToc: true,
|
|
84
|
+
// Remaining opt-in features (#1804).
|
|
85
|
+
githubAlerts: true,
|
|
86
|
+
readingTime: true,
|
|
87
|
+
// owner/repo used to build `owner/repo#123`, `#123`, and SHA autolinks.
|
|
88
|
+
// Included only when settings.githubAutolinksRepo is set; omitted entirely
|
|
89
|
+
// for projects that don't configure a repo (restores old generated-project
|
|
90
|
+
// behaviour — zudo-doc#2321 Wave-0 correctness fix).
|
|
91
|
+
...settings.githubAutolinksRepo ? { githubAutolinks: { repo: settings.githubAutolinksRepo } } : {},
|
|
92
|
+
codeEnrichment: {},
|
|
93
|
+
// codeTabs accepts the `true` shorthand; <CodeGroup> is registered host-side.
|
|
94
|
+
codeTabs: true,
|
|
95
|
+
// ruby — native `<ruby>` markup from `{base}^{ruby}` caret syntax.
|
|
96
|
+
ruby: true,
|
|
97
|
+
// tocExport — object-typed feature; `true` shorthand is rejected by the
|
|
98
|
+
// Rust loader, so pass `{}`.
|
|
99
|
+
tocExport: {},
|
|
100
|
+
imageDimensions: {},
|
|
101
|
+
// warn-only: failOnBroken=false never fails the build.
|
|
102
|
+
linkValidation: { failOnBroken: false },
|
|
103
|
+
// Heading-ID strategy is the single source of truth in settings, mirrored
|
|
104
|
+
// by the host TOC builder so anchors match the rendered IDs.
|
|
105
|
+
headingIds: { strategy: settings.headingIdStrategy }
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function buildPlugins(settings, routeContext) {
|
|
109
|
+
const localeArray = Object.entries(settings.locales).map(([code, locale]) => ({
|
|
110
|
+
code,
|
|
111
|
+
dir: locale.dir
|
|
112
|
+
}));
|
|
113
|
+
const localeRecord = Object.fromEntries(
|
|
114
|
+
Object.entries(settings.locales).map(([code, locale]) => [code, { dir: locale.dir }])
|
|
115
|
+
);
|
|
116
|
+
return [
|
|
117
|
+
// Package-owned route injection — dormant by default (Decision 4). The
|
|
118
|
+
// descriptor is a BARE SPECIFIER, never an imported plugin function: the
|
|
119
|
+
// preset's node-free eval-graph guard (preset.test.ts) bundles this module
|
|
120
|
+
// under --platform=neutral, and importing the plugin would drag its
|
|
121
|
+
// `injectRoute`/`node:*` graph into the config eval. The plugin's `setup`
|
|
122
|
+
// hook reads `options` to (a) emit the route-context virtual module
|
|
123
|
+
// (serializable settings/translations/tagVocabulary only) and (b) derive
|
|
124
|
+
// the route catalog from `settings.locales` / `settings.versions`. Listed
|
|
125
|
+
// FIRST so an injected route is registered before the other plugins'
|
|
126
|
+
// preBuild work runs (ordering is cosmetic — injection happens in `setup`).
|
|
127
|
+
...settings.packageOwnedRoutes ? [
|
|
128
|
+
{
|
|
129
|
+
name: "@takazudo/zudo-doc/plugins/routes",
|
|
130
|
+
options: {
|
|
131
|
+
// Serializable project settings — JSON.stringify-d verbatim into
|
|
132
|
+
// the virtual module. No function-valued fields (verified in
|
|
133
|
+
// src/config/settings.ts), so it round-trips losslessly.
|
|
134
|
+
settings,
|
|
135
|
+
translations: routeContext.translations ?? {},
|
|
136
|
+
tagVocabulary: routeContext.tagVocabulary ?? []
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
] : [],
|
|
140
|
+
...settings.claudeResources ? [
|
|
141
|
+
{
|
|
142
|
+
name: "@takazudo/zudo-doc/plugins/claude-resources",
|
|
143
|
+
options: {
|
|
144
|
+
claudeDir: settings.claudeResources.claudeDir,
|
|
145
|
+
projectRoot: settings.claudeResources.projectRoot,
|
|
146
|
+
docsDir: settings.docsDir
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
] : [],
|
|
150
|
+
...settings.docHistory ? [
|
|
151
|
+
{
|
|
152
|
+
name: "@takazudo/zudo-doc/plugins/doc-history",
|
|
153
|
+
options: {
|
|
154
|
+
docsDir: settings.docsDir,
|
|
155
|
+
locales: localeRecord,
|
|
156
|
+
base: settings.base
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
] : [],
|
|
160
|
+
{
|
|
161
|
+
name: "@takazudo/zudo-doc/plugins/search-index",
|
|
162
|
+
options: {
|
|
163
|
+
docsDir: settings.docsDir,
|
|
164
|
+
locales: localeRecord,
|
|
165
|
+
base: settings.base
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
...settings.llmsTxt ? [
|
|
169
|
+
{
|
|
170
|
+
name: "@takazudo/zudo-doc/plugins/llms-txt",
|
|
171
|
+
options: {
|
|
172
|
+
siteName: settings.siteName,
|
|
173
|
+
siteDescription: settings.siteDescription,
|
|
174
|
+
base: settings.base,
|
|
175
|
+
siteUrl: settings.siteUrl,
|
|
176
|
+
defaultLocaleDir: settings.docsDir,
|
|
177
|
+
locales: localeArray
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
] : []
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
zudoDocPreset
|
|
185
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
function escapeHtml(str) {
|
|
2
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
3
|
+
}
|
|
4
|
+
const ALLOWED_LINK_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
5
|
+
function unescapeHtml(str) {
|
|
6
|
+
return str.replace(/"/g, '"').replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
|
7
|
+
}
|
|
8
|
+
function safeHref(rawCapturedUrl) {
|
|
9
|
+
const decoded = unescapeHtml(rawCapturedUrl);
|
|
10
|
+
let parsed;
|
|
11
|
+
try {
|
|
12
|
+
parsed = new URL(decoded);
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (!ALLOWED_LINK_PROTOCOLS.has(parsed.protocol)) return null;
|
|
17
|
+
return escapeHtml(encodeURI(decoded));
|
|
18
|
+
}
|
|
19
|
+
function renderInline(text) {
|
|
20
|
+
const codeSpans = [];
|
|
21
|
+
let processed = text.replace(/`([^`]+)`/g, (_match, code) => {
|
|
22
|
+
const idx = codeSpans.length;
|
|
23
|
+
codeSpans.push(`<code>${code}</code>`);
|
|
24
|
+
return `%%CODE_${idx}%%`;
|
|
25
|
+
});
|
|
26
|
+
const boldSpans = [];
|
|
27
|
+
processed = processed.replace(/\*\*(.+?)\*\*/g, (_match, inner) => {
|
|
28
|
+
const idx = boldSpans.length;
|
|
29
|
+
boldSpans.push(`<strong>${inner}</strong>`);
|
|
30
|
+
return `%%BOLD_${idx}%%`;
|
|
31
|
+
}).replace(/__(.+?)__/g, (_match, inner) => {
|
|
32
|
+
const idx = boldSpans.length;
|
|
33
|
+
boldSpans.push(`<strong>${inner}</strong>`);
|
|
34
|
+
return `%%BOLD_${idx}%%`;
|
|
35
|
+
});
|
|
36
|
+
processed = processed.replace(/\*(.+?)\*/g, "<em>$1</em>").replace(/(?<!\w)_(.+?)_(?!\w)/g, "<em>$1</em>").replace(/\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g, (_match, label, url) => {
|
|
37
|
+
const href = safeHref(url);
|
|
38
|
+
if (href === null) return `[${label}](${url})`;
|
|
39
|
+
return `<a href="${href}" target="_blank" rel="noopener noreferrer">${label}</a>`;
|
|
40
|
+
});
|
|
41
|
+
processed = processed.replace(/%%BOLD_(\d+)%%/g, (_match, idx) => boldSpans[parseInt(idx, 10)] ?? "");
|
|
42
|
+
return processed.replace(/%%CODE_(\d+)%%/g, (_match, idx) => codeSpans[parseInt(idx, 10)] ?? "");
|
|
43
|
+
}
|
|
44
|
+
function renderListBlock(block, marker, tag) {
|
|
45
|
+
const parts = [];
|
|
46
|
+
let proseLines = [];
|
|
47
|
+
let listItems = [];
|
|
48
|
+
const flushProse = () => {
|
|
49
|
+
if (proseLines.length > 0) {
|
|
50
|
+
parts.push(`<p>${proseLines.map(renderInline).join("<br>")}</p>`);
|
|
51
|
+
proseLines = [];
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const flushList = () => {
|
|
55
|
+
if (listItems.length > 0) {
|
|
56
|
+
parts.push(`<${tag}>${listItems.join("")}</${tag}>`);
|
|
57
|
+
listItems = [];
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
for (const rawLine of block.split("\n")) {
|
|
61
|
+
const line = rawLine.trim();
|
|
62
|
+
if (!line) continue;
|
|
63
|
+
if (marker.test(line)) {
|
|
64
|
+
flushProse();
|
|
65
|
+
listItems.push(`<li>${renderInline(line.replace(marker, ""))}</li>`);
|
|
66
|
+
} else {
|
|
67
|
+
flushList();
|
|
68
|
+
proseLines.push(line);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
flushProse();
|
|
72
|
+
flushList();
|
|
73
|
+
return parts.join("");
|
|
74
|
+
}
|
|
75
|
+
function renderMarkdown(src) {
|
|
76
|
+
const escaped = escapeHtml(src);
|
|
77
|
+
const codeBlocks = [];
|
|
78
|
+
const withPlaceholders = escaped.replace(
|
|
79
|
+
/```(\w*)\n([\s\S]*?)```/g,
|
|
80
|
+
(_match, lang, code) => {
|
|
81
|
+
const idx = codeBlocks.length;
|
|
82
|
+
const langAttr = lang ? ` data-language="${lang}"` : "";
|
|
83
|
+
codeBlocks.push(`<pre${langAttr}><code>${code.trimEnd()}</code></pre>`);
|
|
84
|
+
return `
|
|
85
|
+
%%CODEBLOCK_${idx}%%
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
const blocks = withPlaceholders.split(/\n{2,}/);
|
|
90
|
+
const rendered = blocks.map((block) => {
|
|
91
|
+
const trimmed = block.trim();
|
|
92
|
+
if (!trimmed) return "";
|
|
93
|
+
const cbMatch = trimmed.match(/^%%CODEBLOCK_(\d+)%%$/);
|
|
94
|
+
if (cbMatch) return codeBlocks[parseInt(cbMatch[1] ?? "0", 10)] ?? "";
|
|
95
|
+
if (/^[-*] /m.test(trimmed)) {
|
|
96
|
+
return renderListBlock(trimmed, /^[-*] /, "ul");
|
|
97
|
+
}
|
|
98
|
+
if (/^\d+\. /m.test(trimmed)) {
|
|
99
|
+
return renderListBlock(trimmed, /^\d+\. /, "ol");
|
|
100
|
+
}
|
|
101
|
+
const headingMatch = trimmed.match(/^(#{1,3}) (.+)$/);
|
|
102
|
+
if (headingMatch) {
|
|
103
|
+
const hashes = headingMatch[1] ?? "";
|
|
104
|
+
const headingText = headingMatch[2] ?? "";
|
|
105
|
+
const level = hashes.length;
|
|
106
|
+
return `<h${level + 3}>${renderInline(headingText)}</h${level + 3}>`;
|
|
107
|
+
}
|
|
108
|
+
const lines = trimmed.split("\n").map(renderInline).join("<br>");
|
|
109
|
+
return `<p>${lines}</p>`;
|
|
110
|
+
}).filter(Boolean).join("");
|
|
111
|
+
return rendered;
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
renderMarkdown
|
|
115
|
+
};
|
package/dist/robots.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry for `@takazudo/zudo-doc/robots`.
|
|
3
|
+
*
|
|
4
|
+
* Renders the content of `robots.txt` from project settings.
|
|
5
|
+
* Extracted from `pages/robots.txt.tsx` so the same logic can be
|
|
6
|
+
* consumed by both the showcase page and every `create-zudo-doc`
|
|
7
|
+
* scaffold without copy-drift.
|
|
8
|
+
*
|
|
9
|
+
* ## Usage
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { renderRobots } from "@takazudo/zudo-doc/robots";
|
|
13
|
+
* import { settings } from "@/config/settings";
|
|
14
|
+
*
|
|
15
|
+
* export const contentType = "text/plain";
|
|
16
|
+
* export default () => renderRobots(settings);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/** Minimal settings shape consumed by renderRobots. */
|
|
20
|
+
export interface RobotsSettings {
|
|
21
|
+
/** When true, disallow all crawlers. */
|
|
22
|
+
noindex: boolean;
|
|
23
|
+
/** Base URL of the site, used to construct the Sitemap line. */
|
|
24
|
+
siteUrl?: string;
|
|
25
|
+
/** When true (and siteUrl is set), append a Sitemap: line. */
|
|
26
|
+
sitemap?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the plain-text content for `robots.txt` based on settings.
|
|
30
|
+
*
|
|
31
|
+
* - `noindex: true` → `Disallow: /` with no Sitemap line (advertising a
|
|
32
|
+
* sitemap while disallowing all crawlers is contradictory).
|
|
33
|
+
* - Otherwise → `Allow: /` with an optional `Sitemap:` line when both
|
|
34
|
+
* `siteUrl` and `sitemap` are truthy.
|
|
35
|
+
*/
|
|
36
|
+
export declare function renderRobots(settings: RobotsSettings): string;
|
package/dist/robots.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function renderRobots(settings) {
|
|
2
|
+
if (settings.noindex) {
|
|
3
|
+
return `User-agent: *
|
|
4
|
+
Disallow: /
|
|
5
|
+
`;
|
|
6
|
+
}
|
|
7
|
+
const siteUrlBase = (settings.siteUrl ?? "").replace(/\/$/, "");
|
|
8
|
+
const hasSitemapLine = siteUrlBase !== "" && settings.sitemap;
|
|
9
|
+
const sitemapLine = hasSitemapLine ? `Sitemap: ${siteUrlBase}/sitemap.xml
|
|
10
|
+
` : "";
|
|
11
|
+
return `User-agent: *
|
|
12
|
+
Allow: /
|
|
13
|
+
${sitemapLine}`;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
renderRobots
|
|
17
|
+
};
|