astro-custom-toc 2.0.35 → 2.0.37
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNonEmptyArray } from "@robot-inventor/ts-utils";
|
|
1
2
|
import { fromHtml } from "hast-util-from-html";
|
|
2
3
|
import { h } from "hastscript";
|
|
3
4
|
import { toHtml } from "hast-util-to-html";
|
|
@@ -63,11 +64,10 @@ const generateToc = (options, headings) => {
|
|
|
63
64
|
for (let i = 0; i < currentDepth - heading.depth; i++) {
|
|
64
65
|
parents.pop();
|
|
65
66
|
// eslint-disable-next-line no-magic-numbers
|
|
66
|
-
|
|
67
|
+
const parentNode = parents[parents.length - 1];
|
|
68
|
+
if (!parentNode) {
|
|
67
69
|
throw new Error("Parent node not found. Make sure the headings are sorted by depth.");
|
|
68
70
|
}
|
|
69
|
-
// eslint-disable-next-line no-magic-numbers
|
|
70
|
-
const parentNode = parents[parents.length - 1];
|
|
71
71
|
currentParent = parentNode;
|
|
72
72
|
}
|
|
73
73
|
currentParent.children.push(li);
|
|
@@ -90,13 +90,15 @@ const rehypeCustomToc = (userOptions) => {
|
|
|
90
90
|
* @param vFile.data The VFile data
|
|
91
91
|
*/
|
|
92
92
|
const transformer = (tree, { data }) => {
|
|
93
|
-
if (!data.astro || data.astro.frontmatter
|
|
93
|
+
if (!data.astro || data.astro.frontmatter["showToc"] !== true)
|
|
94
94
|
return;
|
|
95
95
|
/* eslint-disable no-underscore-dangle */
|
|
96
96
|
if (!data.__astroHeadings)
|
|
97
97
|
throw new Error("Headings data not found in the file data.");
|
|
98
98
|
const headings = data.__astroHeadings;
|
|
99
99
|
/* eslint-enable no-underscore-dangle */
|
|
100
|
+
if (!isNonEmptyArray(headings))
|
|
101
|
+
return;
|
|
100
102
|
let tocIndex = 0;
|
|
101
103
|
visit(tree, "comment", (node, index) => {
|
|
102
104
|
if (node.type === "comment" && node.value.trim().toLowerCase() === "toc" && typeof index !== "undefined") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-custom-toc",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.37",
|
|
4
4
|
"description": "Astro Integration to generate a customizable table of contents",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"provenance": true
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"homepage": "https://github.com/Robot-Inventor/astro-custom-toc#readme",
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@astrojs/markdown-remark": "^5.1.0",
|
|
43
|
+
"@robot-inventor/ts-utils": "^0.6.0",
|
|
43
44
|
"@types/hast": "^3.0.4",
|
|
44
45
|
"astro": "^4.5.17",
|
|
45
46
|
"hast-util-from-html": "^2.0.1",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"@changesets/changelog-github": "^0.5.0",
|
|
55
56
|
"@changesets/cli": "^2.27.1",
|
|
56
57
|
"@robot-inventor/eslint-config": "^6.0.0",
|
|
57
|
-
"@robot-inventor/tsconfig-base": "^
|
|
58
|
+
"@robot-inventor/tsconfig-base": "^4.0.0",
|
|
58
59
|
"eslint": "^9.0.0",
|
|
59
60
|
"prettier": "^3.2.5"
|
|
60
61
|
}
|