specra 0.2.66 → 0.2.68

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.
@@ -0,0 +1,43 @@
1
+ import GithubSlugger from 'github-slugger';
2
+ const HEADING_TAG = /^h[1-6]$/;
3
+ /** Concatenate the text nodes beneath a node, as hast-util-to-string would. */
4
+ function textContent(node) {
5
+ if (node.type === 'text')
6
+ return String(node.value ?? '');
7
+ if (Array.isArray(node.children))
8
+ return node.children.map(textContent).join('');
9
+ return '';
10
+ }
11
+ /** Preorder walk over element nodes, i.e. document order. */
12
+ function walkElements(nodes, fn) {
13
+ for (const node of nodes) {
14
+ if (node.type !== 'element')
15
+ continue;
16
+ fn(node);
17
+ if (node.children) {
18
+ walkElements(node.children, fn);
19
+ }
20
+ }
21
+ }
22
+ export function rehypeChangelogIds() {
23
+ return (tree) => {
24
+ const slugger = new GithubSlugger();
25
+ walkElements(tree.children, (node) => {
26
+ // Consume the name rehype-slug already consumed for this heading, keeping
27
+ // the two occurrence counters aligned. The return value is discarded —
28
+ // rehype-slug owns the heading's actual id.
29
+ if (HEADING_TAG.test(node.tagName)) {
30
+ slugger.slug(textContent(node));
31
+ return;
32
+ }
33
+ if (node.tagName !== 'update')
34
+ return;
35
+ const label = node.properties?.label;
36
+ // A label-less update has no identity to anchor. It still renders; it just
37
+ // gets no anchor, no ToC entry and no feed item.
38
+ if (typeof label !== 'string' || !label.trim())
39
+ return;
40
+ node.properties = { ...node.properties, id: slugger.slug(label.trim()) };
41
+ });
42
+ };
43
+ }
@@ -3,10 +3,12 @@
3
3
  * This module provides consistent sidebar logic across the application
4
4
  * to ensure ordering is handled the same way everywhere.
5
5
  */
6
+ import type { BadgeInput } from "./badges.js";
6
7
  export interface SidebarGroup {
7
8
  label: string;
8
9
  path: string;
9
10
  icon?: string;
11
+ badge?: BadgeInput;
10
12
  items: any[];
11
13
  position: number;
12
14
  collapsible: boolean;
@@ -50,6 +52,7 @@ export declare function buildSidebarStructure<T extends {
50
52
  categoryLabel?: string;
51
53
  categoryPosition?: number;
52
54
  categoryIcon?: string;
55
+ categoryBadge?: BadgeInput;
53
56
  categoryCollapsible?: boolean;
54
57
  categoryCollapsed?: boolean;
55
58
  meta: any;
@@ -49,11 +49,14 @@ export function buildSidebarStructure(docs) {
49
49
  docs.forEach((doc) => {
50
50
  const pathParts = doc.filePath.split("/");
51
51
  const folderPath = pathParts.length > 1 ? pathParts.slice(0, -1).join("/") : "";
52
- if (folderPath && doc.categoryLabel) {
52
+ // A `_category_.json` may set a badge without setting a label, so keying
53
+ // this purely off `categoryLabel` would silently drop the badge.
54
+ if (folderPath && (doc.categoryLabel || doc.categoryBadge)) {
53
55
  categoryMetadata.set(folderPath, {
54
56
  label: doc.categoryLabel,
55
57
  position: doc.categoryPosition,
56
58
  icon: doc.categoryIcon,
59
+ badge: doc.categoryBadge,
57
60
  collapsible: doc.categoryCollapsible,
58
61
  collapsed: doc.categoryCollapsed
59
62
  });
@@ -100,6 +103,7 @@ export function buildSidebarStructure(docs) {
100
103
  label: metadata?.label ?? folderLabel,
101
104
  path: currentPath,
102
105
  icon: metadata?.icon,
106
+ badge: metadata?.badge,
103
107
  items: [],
104
108
  position: metadata?.position ?? 999,
105
109
  collapsible: metadata?.collapsible ?? true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specra",
3
- "version": "0.2.66",
3
+ "version": "0.2.68",
4
4
  "description": "A modern documentation library for SvelteKit with built-in versioning, API reference generation, full-text search, and MDX support",
5
5
  "svelte": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -81,6 +81,7 @@
81
81
  "clsx": "^2.1.1",
82
82
  "date-fns": "^4.1.0",
83
83
  "embla-carousel-svelte": "^8.5.1",
84
+ "github-slugger": "^2.0.0",
84
85
  "gray-matter": "^4.0.3",
85
86
  "hast-util-to-html": "^9.0.0",
86
87
  "js-yaml": "^4.1.1",