starlight-cannoli-plugins 2.7.0 → 2.7.1
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/index.d.ts +13 -1
- package/dist/index.js +18 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ import 'vfile';
|
|
|
13
13
|
import 'mdast';
|
|
14
14
|
import 'expressive-code';
|
|
15
15
|
|
|
16
|
+
type TBadgeVariant = "note" | "danger" | "success" | "caution" | "tip" | "default";
|
|
17
|
+
type TIndexMarker = {
|
|
18
|
+
text: string;
|
|
19
|
+
variant: TBadgeVariant;
|
|
20
|
+
};
|
|
21
|
+
|
|
16
22
|
type TOptions = {
|
|
17
23
|
/**
|
|
18
24
|
* Controls how deep the nested group structure can go, where the root directory is level 0.
|
|
@@ -32,7 +38,13 @@ type TOptions = {
|
|
|
32
38
|
* regular sidebar entries. When undefined, no marker is added.
|
|
33
39
|
* @example "★"
|
|
34
40
|
*/
|
|
35
|
-
indexMarker?:
|
|
41
|
+
indexMarker?: TIndexMarker;
|
|
42
|
+
/**
|
|
43
|
+
* Whether sidebar groups should be collapsed by default. Starlight automatically expands
|
|
44
|
+
* the group containing the current page regardless of this setting.
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
collapsed?: boolean;
|
|
36
48
|
};
|
|
37
49
|
/**
|
|
38
50
|
* Starlight plugin that generates a sidebar by parsing markdown links from index.md files.
|
package/dist/index.js
CHANGED
|
@@ -110,7 +110,7 @@ function tryResolveMarkdownFile(href, currentDir) {
|
|
|
110
110
|
}
|
|
111
111
|
return findMarkdownFile(resolved);
|
|
112
112
|
}
|
|
113
|
-
function buildItems(dirPath, currentDepth, maxDepth, visited, indexMarker) {
|
|
113
|
+
function buildItems(dirPath, currentDepth, maxDepth, visited, indexMarker, collapsed) {
|
|
114
114
|
const absDir = path.resolve(dirPath);
|
|
115
115
|
if (visited.has(absDir)) return [];
|
|
116
116
|
visited.add(absDir);
|
|
@@ -125,8 +125,9 @@ function buildItems(dirPath, currentDepth, maxDepth, visited, indexMarker) {
|
|
|
125
125
|
const items = [];
|
|
126
126
|
const indexBaseLabel = fm.title ?? pathSegmentToLabel(path.basename(absDir));
|
|
127
127
|
items.push({
|
|
128
|
-
label:
|
|
129
|
-
slug: normalizeSlug(filePathToSlug(indexFile))
|
|
128
|
+
label: indexBaseLabel,
|
|
129
|
+
slug: normalizeSlug(filePathToSlug(indexFile)),
|
|
130
|
+
...indexMarker && { badge: indexMarker }
|
|
130
131
|
});
|
|
131
132
|
for (const href of extractMarkdownLinks(indexFile)) {
|
|
132
133
|
if (isExternal(href)) continue;
|
|
@@ -143,8 +144,9 @@ function buildItems(dirPath, currentDepth, maxDepth, visited, indexMarker) {
|
|
|
143
144
|
continue;
|
|
144
145
|
const subBaseLabel = subFm.title ?? pathSegmentToLabel(path.basename(subDirPath));
|
|
145
146
|
items.push({
|
|
146
|
-
label:
|
|
147
|
-
slug: normalizeSlug(filePathToSlug(resolvedFile))
|
|
147
|
+
label: subBaseLabel,
|
|
148
|
+
slug: normalizeSlug(filePathToSlug(resolvedFile)),
|
|
149
|
+
...indexMarker && { badge: indexMarker }
|
|
148
150
|
});
|
|
149
151
|
} else {
|
|
150
152
|
const subItems = buildItems(
|
|
@@ -152,7 +154,8 @@ function buildItems(dirPath, currentDepth, maxDepth, visited, indexMarker) {
|
|
|
152
154
|
currentDepth + 1,
|
|
153
155
|
maxDepth,
|
|
154
156
|
visited,
|
|
155
|
-
indexMarker
|
|
157
|
+
indexMarker,
|
|
158
|
+
collapsed
|
|
156
159
|
);
|
|
157
160
|
if (subItems.length === 0) continue;
|
|
158
161
|
if (currentDepth + 1 >= maxDepth) {
|
|
@@ -160,7 +163,8 @@ function buildItems(dirPath, currentDepth, maxDepth, visited, indexMarker) {
|
|
|
160
163
|
} else {
|
|
161
164
|
items.push({
|
|
162
165
|
label: pathSegmentToLabel(path.basename(subDirPath)),
|
|
163
|
-
items: subItems
|
|
166
|
+
items: subItems,
|
|
167
|
+
collapsed
|
|
164
168
|
});
|
|
165
169
|
}
|
|
166
170
|
}
|
|
@@ -178,7 +182,7 @@ function buildItems(dirPath, currentDepth, maxDepth, visited, indexMarker) {
|
|
|
178
182
|
}
|
|
179
183
|
return items;
|
|
180
184
|
}
|
|
181
|
-
function getIndexSourcedSidebarItems(directory, maxDepthNesting = 100, indexMarker) {
|
|
185
|
+
function getIndexSourcedSidebarItems(directory, maxDepthNesting = 100, indexMarker, collapsed = true) {
|
|
182
186
|
const absDir = path.resolve(directory);
|
|
183
187
|
const rootGroupLabel = pathSegmentToLabel(path.basename(absDir));
|
|
184
188
|
const items = buildItems(
|
|
@@ -186,10 +190,11 @@ function getIndexSourcedSidebarItems(directory, maxDepthNesting = 100, indexMark
|
|
|
186
190
|
0,
|
|
187
191
|
maxDepthNesting,
|
|
188
192
|
/* @__PURE__ */ new Set(),
|
|
189
|
-
indexMarker
|
|
193
|
+
indexMarker,
|
|
194
|
+
collapsed
|
|
190
195
|
);
|
|
191
196
|
if (items.length === 0) return [];
|
|
192
|
-
return [{ label: rootGroupLabel, items }];
|
|
197
|
+
return [{ label: rootGroupLabel, items, collapsed }];
|
|
193
198
|
}
|
|
194
199
|
|
|
195
200
|
// src/plugins/starlight-index-sourced-sidebar/index.ts
|
|
@@ -200,13 +205,14 @@ function starlightIndexSourcedSidebar(options) {
|
|
|
200
205
|
hooks: {
|
|
201
206
|
"config:setup": (hookOptions) => {
|
|
202
207
|
const { updateConfig } = hookOptions;
|
|
203
|
-
const { directories, maxDepthNesting = 100, indexMarker } = options;
|
|
208
|
+
const { directories, maxDepthNesting = 100, indexMarker, collapsed = true } = options;
|
|
204
209
|
const sidebarItems = directories.map((directory) => {
|
|
205
210
|
const dirPath = join2(SITE_DOCS_ROOT2, directory);
|
|
206
211
|
const rawItems = getIndexSourcedSidebarItems(
|
|
207
212
|
dirPath,
|
|
208
213
|
maxDepthNesting,
|
|
209
|
-
indexMarker
|
|
214
|
+
indexMarker,
|
|
215
|
+
collapsed
|
|
210
216
|
);
|
|
211
217
|
const rootGroup = rawItems[0];
|
|
212
218
|
if (!rootGroup || !("items" in rootGroup)) return void 0;
|
package/package.json
CHANGED