@t8/docsgen 0.1.39 → 0.1.41
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 +15 -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
|
-
if (elementId)
|
|
451
|
-
|
|
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
|
+
let elementId = element.id || slug.toLowerCase().replace(/_/g, "-");
|
|
450
|
+
if (elementId)
|
|
451
|
+
linkMap[`#${elementId}`] = `${link}${isSectionTitle ? "" : `#${slug}`}`;
|
|
456
452
|
if (singlePage && isSectionTitle) {
|
|
457
|
-
if (navItem)
|
|
453
|
+
if (navItem) {
|
|
454
|
+
element.id = slug;
|
|
458
455
|
navItem.items.push({
|
|
459
|
-
id:
|
|
456
|
+
id: slug,
|
|
460
457
|
title: element.innerHTML.trim()
|
|
461
458
|
});
|
|
459
|
+
}
|
|
462
460
|
} else if (isSectionTitle) {
|
|
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,40 @@ 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
|
-
|
|
46
|
-
elementId = getSlug(element.textContent)
|
|
47
|
-
.toLowerCase()
|
|
48
|
-
.replace(/_/g, "-");
|
|
44
|
+
let elementId = element.id || slug.toLowerCase().replace(/_/g, "-");
|
|
49
45
|
|
|
50
|
-
if (elementId)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
let link = `${root}${contentDir}/${sectionId}`;
|
|
54
|
-
|
|
55
|
-
if (!isSectionTitle) link += `#${elementId}`;
|
|
56
|
-
|
|
57
|
-
linkMap[`#${elementId}`] = link;
|
|
58
|
-
}
|
|
46
|
+
if (elementId)
|
|
47
|
+
linkMap[`#${elementId}`] = `${link}${isSectionTitle ? "" : `#${slug}`}`;
|
|
59
48
|
|
|
60
49
|
if (singlePage && isSectionTitle) {
|
|
61
|
-
if (navItem)
|
|
50
|
+
if (navItem) {
|
|
51
|
+
element.id = slug;
|
|
62
52
|
navItem.items.push({
|
|
63
|
-
id:
|
|
53
|
+
id: slug,
|
|
64
54
|
title: element.innerHTML.trim(),
|
|
65
55
|
});
|
|
56
|
+
}
|
|
66
57
|
} else if (isSectionTitle) {
|
|
67
58
|
if (navItem) nav.push(navItem);
|
|
68
59
|
|
|
69
60
|
navItem = {
|
|
70
|
-
id:
|
|
61
|
+
id: slug,
|
|
71
62
|
title: element.innerHTML.trim(),
|
|
72
63
|
items: [],
|
|
73
64
|
};
|
|
74
65
|
} else if (isSubsectionTitle) {
|
|
75
|
-
if (navItem)
|
|
66
|
+
if (navItem) {
|
|
67
|
+
element.id = slug;
|
|
76
68
|
navItem.items.push({
|
|
77
|
-
id:
|
|
69
|
+
id: slug,
|
|
78
70
|
title: element.innerHTML.trim(),
|
|
79
71
|
});
|
|
72
|
+
}
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
75
|
|