Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit dae7d9f

Browse files
committed
fixes #27
1 parent 9798f5e commit dae7d9f

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

config/search.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,40 @@ const searchPluginConfig = {
1616
fields {
1717
path
1818
}
19+
tableOfContents
1920
}
2021
}
2122
}
2223
`,
2324
index: ["title"],
2425
normalizer: ({ data }) =>
25-
data.allMdx.nodes.map((node) => ({
26-
id: node.id,
27-
title: node.frontmatter.title,
28-
description: node.frontmatter.description,
29-
url: node.fields.path,
30-
isExternal: false,
31-
})),
26+
data.allMdx.nodes.flatMap((node) => {
27+
// return at least the main page ("node")
28+
const returnVal = [
29+
{
30+
id: node.id,
31+
title: node.frontmatter.title,
32+
description: node.frontmatter.description,
33+
url: node.fields.path,
34+
isExternal: false,
35+
toc: node.tableOfContents,
36+
},
37+
];
38+
39+
// add the headers too if they're in ToC
40+
if (node.tableOfContents.items != null) {
41+
node.tableOfContents.items.map((header) =>
42+
returnVal.push({
43+
id: node.id.concat(header.url),
44+
title: node.frontmatter.title.concat(" - ", header.title),
45+
url: node.fields.path.concat(header.url),
46+
isExternal: false,
47+
})
48+
);
49+
}
50+
51+
return returnVal;
52+
}),
3253
},
3354
};
3455

0 commit comments

Comments
 (0)