Skip to content

Commit aac7ef7

Browse files
authored
fix(html): list pages without a document-level stability index (#1061)
The generated index page is built from every page carrying a stability index, so a document that has none is dropped from the listing. A document-level stability index is optional. Documents such as `cli`, `process` and `errors` place stability on their individual sections instead, and `cli` alone carries 50 of them, so having none at the document level says nothing about whether the page belongs in a listing of the documentation. Against the current nodejs/node docs this drops 13 of 68 pages, including `module`, the one the issue reports, along with `process`, `errors` and `cli`. The sidebar, built from the same input by `buildPageList()`, applies no such filter and lists all of them. List every page instead, excluding only the index itself, which is the page doing the listing. The stability badge renders only when the entry has an index, so a page without one no longer produces an empty badge labelled `Stability: undefined`. Fixes: #1055 Signed-off-by: Avocado <ujubongbong@gmail.com>
1 parent d29b063 commit aac7ef7

4 files changed

Lines changed: 66 additions & 13 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@doc-kit/generator-react': patch
3+
---
4+
5+
fix(html): list pages without a document-level stability index

‎packages/react/src/html/ui/components/DocumentationIndex/index.jsx‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { documentationIndex } from '#theme/config';
99
* @typedef {Object} DocumentationIndexEntry
1010
* @property {string} api - Basename of the document, linked as `${api}.html`
1111
* @property {string} name - Human-readable name from the document's heading
12-
* @property {string} index - Stability index (e.g. `'2'` or `'1.1'`)
12+
* @property {string} [index] - Stability index (e.g. `'2'` or `'1.1'`), absent
13+
* on documents that carry stability only on their individual sections
1314
* @property {string} [description] - The document's `llm_description`, or its
1415
* first paragraph, rendered to HTML at build time
1516
*/
@@ -26,13 +27,15 @@ const IndexEntry = ({ api, name, index, description }) => {
2627
<span className={styles.title}>
2728
<span className={styles.name}>{name}</span>
2829

29-
<Badge
30-
size="small"
31-
kind={STABILITY_KINDS[level] ?? 'neutral'}
32-
aria-label={`Stability: ${index}`}
33-
>
34-
{label}
35-
</Badge>
30+
{index !== undefined && (
31+
<Badge
32+
size="small"
33+
kind={STABILITY_KINDS[level] ?? 'neutral'}
34+
aria-label={`Stability: ${index}`}
35+
>
36+
{label}
37+
</Badge>
38+
)}
3639
</span>
3740

3841
{description && (

‎packages/react/src/html/utils/__tests__/config.test.mjs‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const makeEntry = (api, name, path, extra = {}) => ({
5252
api,
5353
path,
5454
heading: { depth: 1, data: { name } },
55+
content: { type: 'root', children: [] },
5556
...extra,
5657
});
5758

@@ -131,7 +132,7 @@ describe('buildPageList', () => {
131132
});
132133

133134
describe('buildDocumentationIndex', () => {
134-
it('lists only pages with a stability index, with their descriptions', () => {
135+
it('lists every page but the index itself, with their descriptions', () => {
135136
const input = [
136137
{
137138
api: 'fs',
@@ -183,6 +184,46 @@ describe('buildDocumentationIndex', () => {
183184
]);
184185
});
185186

187+
it('keeps pages that carry no document-level stability index', () => {
188+
// `process` and `errors` are documented this way: stability lives on their
189+
// individual sections rather than on the document.
190+
const input = [
191+
{
192+
api: 'process',
193+
path: '/process',
194+
heading: { depth: 1, data: { name: 'Process' } },
195+
stability: null,
196+
llm_description: 'Information about the current process.',
197+
content: { type: 'root', children: [] },
198+
},
199+
{
200+
api: 'fs',
201+
path: '/fs',
202+
heading: { depth: 1, data: { name: 'File System' } },
203+
stability: { data: { index: '2' } },
204+
llm_description: 'File system APIs.',
205+
content: { type: 'root', children: [] },
206+
},
207+
];
208+
209+
const result = buildDocumentationIndex(input);
210+
211+
assert.deepStrictEqual(result, [
212+
{
213+
api: 'fs',
214+
name: 'File System',
215+
index: '2',
216+
description: 'File system APIs.',
217+
},
218+
{
219+
api: 'process',
220+
name: 'Process',
221+
index: undefined,
222+
description: 'Information about the current process.',
223+
},
224+
]);
225+
});
226+
186227
it('renders descriptions to HTML, without the links entries cannot nest', () => {
187228
const input = [
188229
{

‎packages/react/src/html/utils/config.mjs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,22 @@ export function buildChunkGroups(input) {
116116

117117
/**
118118
* Pre-compute the entries rendered by the `<DocumentationIndex />` component:
119-
* every page with a stability index, plus its description.
119+
* every page other than the index itself, plus its description.
120+
*
121+
* A document-level stability index is optional. Documents such as `process`
122+
* and `errors` carry stability only on their individual sections, and pages
123+
* that list them by document, this one included, still need to link to them.
120124
*
121125
* @param {Array<import('@doc-kit/core/generators/metadata/types').MetadataEntry>} input
122-
* @returns {Array<{api: string, name: string, index: string, description: string}>}
126+
* @returns {Array<{api: string, name: string, index: string | undefined, description: string}>}
123127
*/
124128
export function buildDocumentationIndex(input) {
125129
return getSortedHeadNodes(input)
126-
.filter(entry => entry.stability)
130+
.filter(entry => entry.api !== 'index')
127131
.map(entry => ({
128132
api: entry.api,
129133
name: entry.heading.data.name,
130-
index: entry.stability.data.index,
134+
index: entry.stability?.data.index,
131135
description: renderAsHTML(parseInline(getEntryDescription(entry), true)),
132136
}));
133137
}

0 commit comments

Comments
 (0)