@clean-jsdoc-theme/dwar

中文文档
5.2.1发布于 2026/10/24MITTypeScriptES Module构建来源已验证近 30 天下载 2.2万

Pure SiteManifest → HTML/CSS/JS renderer for clean-jsdoc-theme

原始使用文档
文档目录7 节
  1. Public API
  2. Usage
  3. What render() emits
  4. Pipeline placement
  5. Notes
  6. Contributors
  7. License

@clean-jsdoc-theme/dwar

Pure SiteManifest → HTML/CSS/JS renderer. Compiles MDX through Preact components from @clean-jsdoc-theme/rang, server-renders each page, bundles the islands in one split esbuild build (a shared chunk + a content-hashed entry chunk per island), and emits CSS.

Public API

  • render(manifest, opts): Promise<RenderResult> — the package's only export: a pure async function returning an in-memory RenderResult (OutputFile[], SearchEntry[], errors, stats). Callers persist the files themselves. A page that fails to compile is skipped and reported in RenderResult.errors, never thrown.

Usage

import { render } from '@clean-jsdoc-theme/dwar';
import { generateSite } from '@clean-jsdoc-theme/setu';
import { writeFile, mkdir } from 'node:fs/promises';
import { dirname, join } from 'node:path';

const manifest = generateSite(saltyCollection);

const result = await render(manifest, {
  theme: {
    tokens: {
      colors: {
        bg: '#ffffff',
        bgMuted: '#f5f5f5',
        fg: '#111111',
        fgMuted: '#666666',
        accent: '#0070f3',
        accentFg: '#ffffff',
        border: '#e5e5e5',
      },
      fonts: { heading: 'Source Serif 4', body: 'Roboto', mono: 'ui-monospace' },
      shiki: { light: 'github-light', dark: 'github-dark' },
      siteName: 'My Docs',
    },
    basePath: '/',
  },
});

const outDir = './dist';
for (const file of result.files) {
  const target = join(outDir, file.path);
  await mkdir(dirname(target), { recursive: true });
  await writeFile(target, file.contents);
}

What render() emits

  • <slug>/index.html per Page. Each <head> includes a pre-hydration theme script (before the stylesheet link) to prevent FOUC; the inline heading-anchors + islands loader scripts run before </body>.
  • <slug>/index.md per content page — the page's MDX body verbatim, co-located with the HTML (for LLMs + the copy-page button). Source-viewer pages emit none.
  • _assets/styles.${buildId}.css — the per-theme :root / [data-theme="dark"] token block plus the prebuilt static utility layer.
  • _assets/search-index.${buildId}.json — the fuzzy search index the cmdk island fetches.
  • _islands/<name>.js per IslandName — content-hashed entry chunks from one split esbuild build, sharing a common Preact + rang chunk.
  • Per-page <script data-island-props>{ "i0": …, "i1": …, … }</script> carrying serialized island props.
  • A copy-page island above the body and a prev/next pager (PageNav) below it on content pages — each gated by ThemeConfig (copyPage / pageNav), never on source pages.
  • RenderResult.search — one SearchEntry per non-hidden page, ready for downstream indexing.

For a localized build (RenderOptions.locale), the SSR tree is wrapped in a bhasha LanguageProvider, an __i18n payload seeds every island root (no hydration drift), <html lang> and hreflang alternates are set, and the language switcher is mounted. A build with no locale is byte-identical to before.

kind: 'source' pages skip MDX entirely: the raw source stays in the SSR <pre> (off the JSON payload) and the code-viewer island lazy-loads Monaco from a CDN to enhance it.

Pipeline placement

SiteManifest ──► dwar.render ──► OutputFile[] ──► caller writes ──► static site
                     │
                     ├── MDX via @mdx-js/mdx + rang.defaultMdxComponents
                     ├── SSR via preact-render-to-string + rang.Layout
                     ├── Island markers wrapping rang.ISLAND_REGISTRY entries
                     ├── Islands bundled via esbuild (shared chunk + per-island entry)
                     └── CSS: per-theme token block + prebuilt utility layer

Notes

  • render() is pure: no fs, no process.cwd, no logging. Persistence is the caller's responsibility. The one disk touch is the opt-in island-bundle cache (RenderOptions.islandCacheDir); omit it and render() touches no disk at all.
  • CSS is compiled once at dwar's own build time. scripts/build-css.mjs runs the Tailwind v4 CLI over rang's + dwar's source and inlines the result into src/generated/utility-css.ts. Tailwind never runs at the consumer's jsdoc build, so render() stays pure and users need no Tailwind config; only the :root / [data-theme="dark"] token block is emitted per ThemeConfig at render time.
  • A defensive {@link Foo} → `@link Foo` preprocessor in src/mdx.ts is kept as a safety net. setu now resolves links upstream, so only genuinely-unresolvable tags reach this code, where the inline-code fallback keeps the page compiling.

Contributors

Thanks to everyone who has helped build clean-jsdoc-theme.

Contributors

License

MIT.

版本与发布记录

@clean-jsdoc-theme/dwar 共发布 18 个版本,首次发布于 2026/06/10;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.2.1latest2026/10/2416 天前
5.2.02026/08/282 个月前
5.1.12026/07/293 个月前
5.1.02026/07/243 个月前
5.0.82026/07/183 个月前
5.0.72026/07/074 个月前

其他发布通道:next → 5.0.0-alpha.0。

关于 @clean-jsdoc-theme/dwar 的常见问题

@clean-jsdoc-theme/dwar 是什么?

Pure SiteManifest → HTML/CSS/JS renderer for clean-jsdoc-theme

如何安装 @clean-jsdoc-theme/dwar?

在项目目录运行 npm install @clean-jsdoc-theme/dwar,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:preact(^10.22.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@clean-jsdoc-theme/dwar 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@clean-jsdoc-theme/dwar 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@clean-jsdoc-theme/dwar 可以商用吗?

@clean-jsdoc-theme/dwar 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@clean-jsdoc-theme/dwar 的下载量有多少?

根据 npm 官方下载统计,@clean-jsdoc-theme/dwar 在 2026/10/10 – 2026/11/08 这 30 天内被下载 21,765 次,日均约 726 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@clean-jsdoc-theme/dwar 还在维护吗?

最新版本 5.2.1 发布于 2026/10/24(16 天前);至今共发布 18 个版本,其中过去 12 个月发布了 18 个;首次发布于 2026/06/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。