astro-custom-toc 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -61,11 +61,12 @@ const generateToc = (options, headings) => {
|
|
|
61
61
|
// The current heading is at a shallower level than the previous one.
|
|
62
62
|
// eslint-disable-next-line id-length
|
|
63
63
|
for (let i = 0; i < currentDepth - heading.depth; i++) {
|
|
64
|
-
|
|
64
|
+
parents.pop();
|
|
65
|
+
// eslint-disable-next-line no-magic-numbers
|
|
66
|
+
const parentNode = parents[parents.length - 1];
|
|
65
67
|
if (!parentNode)
|
|
66
68
|
throw new Error("Parent node not found. Make sure the headings are sorted by depth.");
|
|
67
|
-
|
|
68
|
-
currentParent = parents[parents.length - 1];
|
|
69
|
+
currentParent = parentNode;
|
|
69
70
|
}
|
|
70
71
|
currentParent.children.push(li);
|
|
71
72
|
currentDepth = heading.depth;
|
|
@@ -89,17 +90,17 @@ export const rehypeCustomToc = (userOptions) => {
|
|
|
89
90
|
const transformer = (tree, { data }) => {
|
|
90
91
|
if (!data.astro || data.astro.frontmatter.showToc !== true)
|
|
91
92
|
return;
|
|
93
|
+
/* eslint-disable no-underscore-dangle */
|
|
94
|
+
if (!data.__astroHeadings)
|
|
95
|
+
throw new Error("Headings data not found in the file data.");
|
|
96
|
+
const headings = data.__astroHeadings;
|
|
97
|
+
/* eslint-enable no-underscore-dangle */
|
|
92
98
|
let tocIndex = 0;
|
|
93
99
|
visit(tree, "comment", (node, index) => {
|
|
94
100
|
if (node.type === "comment" && node.value.trim().toLowerCase() === "toc" && typeof index !== "undefined") {
|
|
95
101
|
tocIndex = index;
|
|
96
102
|
}
|
|
97
103
|
});
|
|
98
|
-
/* eslint-disable no-underscore-dangle */
|
|
99
|
-
if (!data.__astroHeadings)
|
|
100
|
-
throw new Error("Headings data not found in the file data.");
|
|
101
|
-
const headings = data.__astroHeadings;
|
|
102
|
-
/* eslint-enable no-underscore-dangle */
|
|
103
104
|
const toc = generateToc(options, headings);
|
|
104
105
|
if (tocIndex) {
|
|
105
106
|
// eslint-disable-next-line no-magic-numbers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-custom-toc",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Astro Integration to generate a customizable table of contents",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"provenance": true
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@changesets/changelog-github": "^0.5.0",
|
|
55
55
|
"@changesets/cli": "^2.27.1",
|
|
56
|
-
"@robot-inventor/eslint-config": "^0.
|
|
56
|
+
"@robot-inventor/eslint-config": "^0.2.0",
|
|
57
57
|
"eslint": "^9.0.0",
|
|
58
58
|
"prettier": "^3.2.5"
|
|
59
59
|
}
|