@t8/docsgen 0.1.39 → 0.1.40
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.
- package/dist/bin.js +15 -15
- package/package.json +1 -1
- package/src/bin/getParsedContent.ts +16 -22
package/dist/bin.js
CHANGED
|
@@ -443,35 +443,35 @@ function buildNav(ctx, dom) {
|
|
|
443
443
|
let tagName = element.tagName.toLowerCase();
|
|
444
444
|
let isSectionTitle = tagName === "h2";
|
|
445
445
|
let isSubsectionTitle = tagName === "h3";
|
|
446
|
-
let
|
|
447
|
-
let
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
element.id = elementId;
|
|
452
|
-
let link = `${root}${contentDir}/${sectionId}`;
|
|
453
|
-
if (!isSectionTitle) link += `#${elementId}`;
|
|
454
|
-
linkMap[`#${elementId}`] = link;
|
|
455
|
-
}
|
|
446
|
+
let slug = getSlug(element.textContent);
|
|
447
|
+
let sectionId = isSectionTitle ? slug : navItem?.id ?? "";
|
|
448
|
+
let link = `${root}${contentDir}/${sectionId}`;
|
|
449
|
+
if (!isSectionTitle) link += `#${slug}`;
|
|
450
|
+
linkMap[`#${slug}`] = link;
|
|
456
451
|
if (singlePage && isSectionTitle) {
|
|
457
|
-
if (navItem)
|
|
452
|
+
if (navItem) {
|
|
453
|
+
element.id = slug;
|
|
458
454
|
navItem.items.push({
|
|
459
|
-
id:
|
|
455
|
+
id: slug,
|
|
460
456
|
title: element.innerHTML.trim()
|
|
461
457
|
});
|
|
458
|
+
}
|
|
462
459
|
} else if (isSectionTitle) {
|
|
460
|
+
element.id = slug;
|
|
463
461
|
if (navItem) nav.push(navItem);
|
|
464
462
|
navItem = {
|
|
465
|
-
id:
|
|
463
|
+
id: slug,
|
|
466
464
|
title: element.innerHTML.trim(),
|
|
467
465
|
items: []
|
|
468
466
|
};
|
|
469
467
|
} else if (isSubsectionTitle) {
|
|
470
|
-
if (navItem)
|
|
468
|
+
if (navItem) {
|
|
469
|
+
element.id = slug;
|
|
471
470
|
navItem.items.push({
|
|
472
|
-
id:
|
|
471
|
+
id: slug,
|
|
473
472
|
title: element.innerHTML.trim()
|
|
474
473
|
});
|
|
474
|
+
}
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
if (navItem) nav.push(navItem);
|
package/package.json
CHANGED
|
@@ -36,47 +36,41 @@ function buildNav(ctx: Context, dom: JSDOM) {
|
|
|
36
36
|
|
|
37
37
|
let isSectionTitle = tagName === "h2";
|
|
38
38
|
let isSubsectionTitle = tagName === "h3";
|
|
39
|
+
let slug = getSlug(element.textContent);
|
|
39
40
|
|
|
40
|
-
let sectionId = isSectionTitle
|
|
41
|
-
|
|
42
|
-
: (navItem?.id ?? "");
|
|
43
|
-
let elementId = element.id;
|
|
41
|
+
let sectionId = isSectionTitle ? slug : (navItem?.id ?? "");
|
|
42
|
+
let link = `${root}${contentDir}/${sectionId}`;
|
|
44
43
|
|
|
45
|
-
if (!
|
|
46
|
-
elementId = getSlug(element.textContent)
|
|
47
|
-
.toLowerCase()
|
|
48
|
-
.replace(/_/g, "-");
|
|
44
|
+
if (!isSectionTitle) link += `#${slug}`;
|
|
49
45
|
|
|
50
|
-
|
|
51
|
-
element.id = elementId;
|
|
52
|
-
|
|
53
|
-
let link = `${root}${contentDir}/${sectionId}`;
|
|
54
|
-
|
|
55
|
-
if (!isSectionTitle) link += `#${elementId}`;
|
|
56
|
-
|
|
57
|
-
linkMap[`#${elementId}`] = link;
|
|
58
|
-
}
|
|
46
|
+
linkMap[`#${slug}`] = link;
|
|
59
47
|
|
|
60
48
|
if (singlePage && isSectionTitle) {
|
|
61
|
-
if (navItem)
|
|
49
|
+
if (navItem) {
|
|
50
|
+
element.id = slug;
|
|
62
51
|
navItem.items.push({
|
|
63
|
-
id:
|
|
52
|
+
id: slug,
|
|
64
53
|
title: element.innerHTML.trim(),
|
|
65
54
|
});
|
|
55
|
+
}
|
|
66
56
|
} else if (isSectionTitle) {
|
|
57
|
+
element.id = slug;
|
|
58
|
+
|
|
67
59
|
if (navItem) nav.push(navItem);
|
|
68
60
|
|
|
69
61
|
navItem = {
|
|
70
|
-
id:
|
|
62
|
+
id: slug,
|
|
71
63
|
title: element.innerHTML.trim(),
|
|
72
64
|
items: [],
|
|
73
65
|
};
|
|
74
66
|
} else if (isSubsectionTitle) {
|
|
75
|
-
if (navItem)
|
|
67
|
+
if (navItem) {
|
|
68
|
+
element.id = slug;
|
|
76
69
|
navItem.items.push({
|
|
77
|
-
id:
|
|
70
|
+
id: slug,
|
|
78
71
|
title: element.innerHTML.trim(),
|
|
79
72
|
});
|
|
73
|
+
}
|
|
80
74
|
}
|
|
81
75
|
}
|
|
82
76
|
|