|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +import { readFile } from 'node:fs/promises'; |
| 4 | +import { join } from 'node:path'; |
| 5 | + |
| 6 | +import getConfig from '../../utils/configuration/index.mjs'; |
| 7 | +import { writeFile } from '../../utils/file.mjs'; |
| 8 | +import buildContent from '../jsx-ast/utils/buildContent.mjs'; |
| 9 | +import { processJSXEntries } from '../web/utils/processing.mjs'; |
| 10 | + |
| 11 | +/** |
| 12 | + * Generates a single `all.html` file containing every API documentation |
| 13 | + * module rendered through the `web` generator pipeline. |
| 14 | + * |
| 15 | + * @type {import('./types').Generator['generate']} |
| 16 | + */ |
| 17 | +export async function generate(input) { |
| 18 | + const config = getConfig('web-all'); |
| 19 | + |
| 20 | + const template = await readFile(config.templatePath, 'utf-8'); |
| 21 | + |
| 22 | + // Match `legacy-html-all`: skip the synthetic `index` entries. |
| 23 | + const entries = input.filter(entry => entry.api !== 'index'); |
| 24 | + |
| 25 | + // Build a single combined JSXContent that wraps every entry's content in |
| 26 | + // one Layout component, mirroring how `jsx-ast` produces per-module pages. |
| 27 | + const combined = await buildContent(entries, { |
| 28 | + api: 'all', |
| 29 | + path: '/all', |
| 30 | + basename: 'all.html', |
| 31 | + heading: { |
| 32 | + type: 'heading', |
| 33 | + depth: 1, |
| 34 | + children: [{ type: 'text', value: 'All' }], |
| 35 | + data: { name: 'All', text: 'All', slug: 'all' }, |
| 36 | + }, |
| 37 | + }); |
| 38 | + |
| 39 | + // Pass the original metadata entries as the sidebar source so `all.html` |
| 40 | + // exposes the same navigation as the per-module pages produced by `web`. |
| 41 | + const sidebarEntries = entries.map(entry => ({ data: entry })); |
| 42 | + |
| 43 | + const { results, css, chunks } = await processJSXEntries( |
| 44 | + [combined], |
| 45 | + template, |
| 46 | + sidebarEntries |
| 47 | + ); |
| 48 | + |
| 49 | + if (config.output) { |
| 50 | + for (const { html, path } of results) { |
| 51 | + await writeFile(join(config.output, `${path}.html`), html, 'utf-8'); |
| 52 | + } |
| 53 | + |
| 54 | + for (const chunk of chunks) { |
| 55 | + await writeFile(join(config.output, chunk.fileName), chunk.code, 'utf-8'); |
| 56 | + } |
| 57 | + |
| 58 | + await writeFile(join(config.output, 'styles.css'), css, 'utf-8'); |
| 59 | + } |
| 60 | + |
| 61 | + return { html: results[0].html.toString(), css }; |
| 62 | +} |
0 commit comments