vitepress-allyouneed 0.3.0-beta.1 → 0.3.0-beta.2
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/CHANGELOG.md +4 -0
- package/dist/index.cjs +55 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -34
- package/dist/index.js.map +1 -1
- package/dist/vitepress.cjs +55 -34
- package/dist/vitepress.cjs.map +1 -1
- package/dist/vitepress.js +55 -34
- package/dist/vitepress.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2426,12 +2426,15 @@ function injectViewsSidebar(sidebar, options) {
|
|
|
2426
2426
|
}
|
|
2427
2427
|
}
|
|
2428
2428
|
}
|
|
2429
|
-
const base = options.base.endsWith("/") ? options.base : options.base + "/";
|
|
2430
2429
|
const prefix = options.views.urlPrefix ? options.views.urlPrefix.replace(/^\/+|\/+$/g, "") : "";
|
|
2431
2430
|
if (prefix) {
|
|
2432
|
-
const persPath =
|
|
2431
|
+
const persPath = `/${prefix}/`;
|
|
2433
2432
|
if (!sidebar[persPath]) {
|
|
2434
|
-
sidebar[persPath] = buildPerspectivesFallbackSidebar(
|
|
2433
|
+
sidebar[persPath] = buildPerspectivesFallbackSidebar(
|
|
2434
|
+
sidebar,
|
|
2435
|
+
group,
|
|
2436
|
+
options.base.endsWith("/") ? options.base : options.base + "/"
|
|
2437
|
+
);
|
|
2435
2438
|
}
|
|
2436
2439
|
}
|
|
2437
2440
|
return sidebar;
|
|
@@ -2439,40 +2442,32 @@ function injectViewsSidebar(sidebar, options) {
|
|
|
2439
2442
|
return [group];
|
|
2440
2443
|
}
|
|
2441
2444
|
function buildPerspectivesFallbackSidebar(allSidebars, group, base) {
|
|
2442
|
-
const out = [{ text: "Home", link:
|
|
2445
|
+
const out = [{ text: "Home", link: "/" }];
|
|
2443
2446
|
const topPaths = Object.keys(allSidebars).filter(
|
|
2444
2447
|
(p) => p !== base && !p.endsWith("/_perspectives_/")
|
|
2445
2448
|
);
|
|
2446
2449
|
for (const p of topPaths) {
|
|
2447
2450
|
const seg = p.replace(/^\/|\/$/g, "").split("/").filter(Boolean).pop() ?? p;
|
|
2448
2451
|
const text = seg.charAt(0).toUpperCase() + seg.slice(1);
|
|
2449
|
-
|
|
2452
|
+
const b = base.endsWith("/") ? base : base + "/";
|
|
2453
|
+
const stripped = b !== "/" && p.startsWith(b) ? "/" + p.slice(b.length) : p;
|
|
2454
|
+
out.push({ text, link: stripped });
|
|
2450
2455
|
}
|
|
2451
2456
|
out.push(group);
|
|
2452
2457
|
return out;
|
|
2453
2458
|
}
|
|
2454
2459
|
function buildViewsGroup(options) {
|
|
2455
2460
|
const { enabled, names, sidebarText, urlPrefix } = options.views;
|
|
2456
|
-
const base = options.base.endsWith("/") ? options.base.slice(0, -1) : options.base;
|
|
2457
2461
|
const prefixSeg = urlPrefix ? `/${urlPrefix}` : "";
|
|
2458
2462
|
const items = [];
|
|
2459
2463
|
if (enabled.graph) {
|
|
2460
|
-
items.push({
|
|
2461
|
-
text: sidebarText.graph,
|
|
2462
|
-
link: `${base}${prefixSeg}/${names.graph}`
|
|
2463
|
-
});
|
|
2464
|
+
items.push({ text: sidebarText.graph, link: `${prefixSeg}/${names.graph}` });
|
|
2464
2465
|
}
|
|
2465
2466
|
if (enabled.stats) {
|
|
2466
|
-
items.push({
|
|
2467
|
-
text: sidebarText.stats,
|
|
2468
|
-
link: `${base}${prefixSeg}/${names.stats}`
|
|
2469
|
-
});
|
|
2467
|
+
items.push({ text: sidebarText.stats, link: `${prefixSeg}/${names.stats}` });
|
|
2470
2468
|
}
|
|
2471
2469
|
if (enabled.tags) {
|
|
2472
|
-
items.push({
|
|
2473
|
-
text: sidebarText.tags,
|
|
2474
|
-
link: `${base}${prefixSeg}/${names.tags}`
|
|
2475
|
-
});
|
|
2470
|
+
items.push({ text: sidebarText.tags, link: `${prefixSeg}/${names.tags}` });
|
|
2476
2471
|
}
|
|
2477
2472
|
if (items.length === 0) return null;
|
|
2478
2473
|
return {
|
|
@@ -2698,13 +2693,34 @@ function generateSidebar(index, options, autoOptions = {}) {
|
|
|
2698
2693
|
}
|
|
2699
2694
|
const root = buildTree2(visible);
|
|
2700
2695
|
const layout = autoOptions.layout ?? "tree";
|
|
2696
|
+
let result;
|
|
2701
2697
|
if (layout === "per-folder") {
|
|
2702
|
-
|
|
2698
|
+
result = toPerFolderSidebar(root, opts, options, index);
|
|
2699
|
+
} else if (layout === "flat") {
|
|
2700
|
+
result = toFlatSidebar(root, opts);
|
|
2701
|
+
} else {
|
|
2702
|
+
result = toTreeSidebar(root, opts, index, options);
|
|
2703
2703
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2704
|
+
stripBaseFromConfig(result, options.base);
|
|
2705
|
+
return result;
|
|
2706
|
+
}
|
|
2707
|
+
function stripBaseFromConfig(cfg, base) {
|
|
2708
|
+
if (Array.isArray(cfg)) {
|
|
2709
|
+
stripBaseFromItems(cfg, base);
|
|
2710
|
+
} else {
|
|
2711
|
+
for (const k of Object.keys(cfg)) {
|
|
2712
|
+
stripBaseFromItems(cfg[k], base);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
function stripBaseFromItems(items, base) {
|
|
2717
|
+
const b = base.endsWith("/") ? base : base + "/";
|
|
2718
|
+
for (const it of items) {
|
|
2719
|
+
if (it.link && b !== "/" && it.link.startsWith(b)) {
|
|
2720
|
+
it.link = "/" + it.link.slice(b.length);
|
|
2721
|
+
}
|
|
2722
|
+
if (it.items) stripBaseFromItems(it.items, base);
|
|
2706
2723
|
}
|
|
2707
|
-
return toTreeSidebar(root, opts, index, options);
|
|
2708
2724
|
}
|
|
2709
2725
|
function buildTree2(files) {
|
|
2710
2726
|
const root = newNode("");
|
|
@@ -2905,7 +2921,6 @@ function walkDirs(node, out) {
|
|
|
2905
2921
|
}
|
|
2906
2922
|
function toPerFolderSidebar(root, opts, options, index) {
|
|
2907
2923
|
const out = {};
|
|
2908
|
-
const base = options.base.endsWith("/") ? options.base : options.base + "/";
|
|
2909
2924
|
const rootItems = [];
|
|
2910
2925
|
const sortedRootFiles = [...root.files].sort((a, b) => compareEntries(a, b, opts));
|
|
2911
2926
|
for (const f of sortedRootFiles) {
|
|
@@ -2923,13 +2938,13 @@ function toPerFolderSidebar(root, opts, options, index) {
|
|
|
2923
2938
|
/* isTopLevel */
|
|
2924
2939
|
true
|
|
2925
2940
|
)) {
|
|
2926
|
-
const firstUrl = child.dirIndex && !child.dirIndexEmpty ? child.dirIndex.url : findFirstPageUrl(child, opts) ??
|
|
2941
|
+
const firstUrl = child.dirIndex && !child.dirIndexEmpty ? child.dirIndex.url : findFirstPageUrl(child, opts) ?? `/${key}/`;
|
|
2927
2942
|
rootItems.push({ text: labelText, link: firstUrl });
|
|
2928
2943
|
} else {
|
|
2929
2944
|
rootItems.push({ text: labelText });
|
|
2930
2945
|
}
|
|
2931
2946
|
}
|
|
2932
|
-
if (rootItems.length > 0) out[
|
|
2947
|
+
if (rootItems.length > 0) out["/"] = rootItems;
|
|
2933
2948
|
for (const key of topKeys) {
|
|
2934
2949
|
const child = root.children.get(key);
|
|
2935
2950
|
const items = renderNode(
|
|
@@ -2956,7 +2971,7 @@ function toPerFolderSidebar(root, opts, options, index) {
|
|
|
2956
2971
|
});
|
|
2957
2972
|
}
|
|
2958
2973
|
sidebar.push(...items);
|
|
2959
|
-
out[
|
|
2974
|
+
out[`/${key}/`] = sidebar;
|
|
2960
2975
|
}
|
|
2961
2976
|
return out;
|
|
2962
2977
|
}
|
|
@@ -2970,7 +2985,7 @@ function generateNav(index, options, autoOptions = {}) {
|
|
|
2970
2985
|
}
|
|
2971
2986
|
const root = buildTree2(visible);
|
|
2972
2987
|
const base = options.base.endsWith("/") ? options.base : options.base + "/";
|
|
2973
|
-
const out = [{ text: opts.homeNavText, link:
|
|
2988
|
+
const out = [{ text: opts.homeNavText, link: "/" }];
|
|
2974
2989
|
const topKeys = [...root.children.keys()].sort();
|
|
2975
2990
|
for (const key of topKeys) {
|
|
2976
2991
|
const child = root.children.get(key);
|
|
@@ -2978,16 +2993,22 @@ function generateNav(index, options, autoOptions = {}) {
|
|
|
2978
2993
|
continue;
|
|
2979
2994
|
}
|
|
2980
2995
|
const text = computeGroupText(child.path, child.dirIndex, opts);
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
link
|
|
2986
|
-
|
|
2987
|
-
});
|
|
2996
|
+
let link;
|
|
2997
|
+
if (child.dirIndex) {
|
|
2998
|
+
link = stripBase(child.dirIndex.url, base);
|
|
2999
|
+
} else {
|
|
3000
|
+
link = `/${key}/`;
|
|
3001
|
+
}
|
|
3002
|
+
const escapedPrefix = `/${key}/`.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3003
|
+
out.push({ text, link, activeMatch: "^" + escapedPrefix });
|
|
2988
3004
|
}
|
|
2989
3005
|
return out;
|
|
2990
3006
|
}
|
|
3007
|
+
function stripBase(url, base) {
|
|
3008
|
+
const b = base.endsWith("/") ? base : base + "/";
|
|
3009
|
+
if (b === "/" || !url.startsWith(b)) return url;
|
|
3010
|
+
return "/" + url.slice(b.length);
|
|
3011
|
+
}
|
|
2991
3012
|
function compareEntries(a, b, opts) {
|
|
2992
3013
|
if (opts.sortBy === "title") {
|
|
2993
3014
|
return opts.formatItemTitle(a).localeCompare(opts.formatItemTitle(b));
|