Skip to content

Commit 5eaf2b0

Browse files
committed
put index first
1 parent ce462a5 commit 5eaf2b0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/generators/jsx-ast/constants.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@ export const AST_NODE_TYPES = {
8686
EXPRESSION_STATEMENT: 'ExpressionStatement',
8787
},
8888
};
89+
90+
// These positions are explicity before anything else
91+
export const OVERRIDDEN_POSITIONS = [
92+
'index', // https://github.com/nodejs/node/blob/main/doc/api/index.md
93+
'synopsis', // https://github.com/nodejs/node/blob/main/doc/api/synopsis.md
94+
'documentation', // https://github.com/nodejs/node/blob/main/doc/api/documentation.md
95+
];

src/generators/jsx-ast/index.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OVERRIDDEN_POSITIONS } from './constants.mjs';
12
import buildContent from './utils/buildContent.mjs';
23
import {
34
getCompatibleVersions,
@@ -34,7 +35,19 @@ export default {
3435
// Get sorted primary heading nodes
3536
const headNodes = entries
3637
.filter(node => node.heading.depth === 1)
37-
.sort((a, b) => a.heading.data.name.localeCompare(b.heading.data.name));
38+
.sort((a, b) => {
39+
const ai = OVERRIDDEN_POSITIONS.indexOf(a.api),
40+
bi = OVERRIDDEN_POSITIONS.indexOf(b.api);
41+
// If this is in OVERRIDDEN_POSITIONS, it must come first
42+
return ai !== -1 && bi !== -1
43+
? ai - bi
44+
: ai !== -1
45+
? -1
46+
: bi !== -1
47+
? 1
48+
: // Just compare headings
49+
a.heading.data.name.localeCompare(b.heading.data.name);
50+
});
3851

3952
// Generate table of contents
4053
const docPages = headNodes.map(node => [

0 commit comments

Comments
 (0)