diff --git a/package.json b/package.json index 7614d84..16976b2 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,9 @@ "ignoreMissing": [ "@algolia/client-search" ] + }, + "patchedDependencies": { + "vitepress-sidebar": "patches/vitepress-sidebar.patch" } } } diff --git a/patches/vitepress-sidebar.patch b/patches/vitepress-sidebar.patch new file mode 100644 index 0000000..a4e3f47 --- /dev/null +++ b/patches/vitepress-sidebar.patch @@ -0,0 +1,8 @@ +diff --git a/dist/index.js b/dist/index.js +index 636633301d69a15f963ba6f2ed97d7ae3b6472e4..075d9ecac65f18b83b9c97e6af6842672f10d6c4 100644 +--- a/dist/index.js ++++ b/dist/index.js +@@ -1 +1 @@ +-import{readFileSync as e,readdirSync as t,statSync as r,existsSync as o}from"fs";import{join as n,resolve as a}from"path";import l from"gray-matter";import{globSync as s}from"glob";export default class i{static generateSidebar(e){const t={},r=Array.isArray(e);let o,a,l=!1;if(arguments.length>1)throw new Error("You must pass 1 argument, see the documentation for details.");o=void 0===e?[{}]:Array.isArray(e)?e:[e];for(let e=0;e0){const e=c.filter((e=>-1!==d.manualSortFileNameByPriority?.indexOf(e))),t=c.filter((e=>-1===d.manualSortFileNameByPriority?.indexOf(e)));e.sort(((e,t)=>d.manualSortFileNameByPriority.indexOf(e)-d.manualSortFileNameByPriority.indexOf(t))),c=[...e,...t]}let p=c.map((t=>{const s=a(n,t);let c=`${l}/${t}`.replace(/\/{2}/,"/").replace(/(index)?\.md$/,"");if(d.documentRootPath&&c.startsWith(d.documentRootPath)&&(c=c.replace(new RegExp(`^${d.documentRootPath}`,"g"),""),d.scanStartPath||d.resolvePath?(c=c.replace(/^\//g,""),d.scanStartPath&&(c=c.replace(new RegExp(`^${d.scanStartPath}`,"g"),"")),c=c.replace(/^\/(?!$)/g,""),"/"===c&&(c="index.md")):c.startsWith("/")||(c=`/${c}`)),/\.vitepress/.test(s))return null;if(/node_modules/.test(s))return null;if(1===e&&"index.md"===t&&!d.includeRootIndexFile)return null;if(1!==e&&"index.md"===t&&!d.includeFolderIndexFile)return null;if(!d.includeDotFiles&&/^\./.test(t))return null;if(!m.includes(t))return null;if(r(s).isDirectory()){if(d.excludeFolders?.includes(t))return null;let r,n=i.generateSidebarItem(e+1,s,c,t,d)||[],l=!1,u=i.getTitleFromMd(t,s,d,!0,(()=>{l=!0})),m=s,p=!1;const F=`${s}/index.md`,y=n.find((e=>e.text===t));return d.convertSameNameSubFileToGroupIndexPage&&y&&(m=a(s,`${y.text}.md`),u=i.getTitleFromMd(t,m,d,!1,(()=>{l=!0})),r=d.folderLinkNotIncludesFileName?`${c}/`:y.link,n=n.filter((e=>e.text!==t))),o(F)&&(d.includeFolderIndexFile&&(p=!0),d.useFolderLinkFromIndexFile&&(p=!0,m=F,r=`${c}/index.md`),d.useFolderTitleFromIndexFile&&!l&&(p=!0,m=F,u=i.getTitleFromMd("index",m,d,!1))),r&&!1!==d.includeEmptyFolder||d.includeEmptyFolder||n.length>0||p?{text:u,...r?{link:r}:{},...n.length>0?{items:n}:{},...null===d.collapsed||void 0===d.collapsed||n.length<1?{}:{collapsed:e>=d.collapseDepth&&d.collapsed},...d.sortMenusByFrontmatterOrder?{order:i.getOrderFromFrontmatter(m,d.frontmatterOrderDefaultValue)}:{},...d.sortMenusByFrontmatterDate?{date:i.getDateFromFrontmatter(s)}:{}}:null}if(s.endsWith(".md")){if(d.excludeFiles?.includes(t)||i.getExcludeFromFrontmatter(s,d.excludeFilesByFrontmatterFieldName))return null;let e;const r=t.replace(/\.md$/,"");return e=d.convertSameNameSubFileToGroupIndexPage&&u===r?r:i.getTitleFromMd(t,s,d,!1),{text:e,link:c,...d.sortMenusByFrontmatterOrder?{order:i.getOrderFromFrontmatter(s,d.frontmatterOrderDefaultValue)}:{},...d.sortMenusByFrontmatterDate?{date:i.getDateFromFrontmatter(s)}:{}}}return null})).filter((e=>null!==e));return d.sortMenusByName&&(p=i.sortByObjectKey({arr:p,key:"text",desc:d.sortMenusOrderByDescending})),d.sortMenusByFileDatePrefix&&(p=i.sortByObjectKey({arr:p,key:"text",desc:d.sortMenusOrderByDescending,dateSortFromTextWithPrefix:!0,datePrefixSeparator:d.prefixSeparator})),d.sortMenusByFrontmatterOrder&&(p=i.sortByObjectKey({arr:p,key:"order",desc:d.sortMenusOrderByDescending}),i.deepDeleteKey(p,"order")),d.sortMenusByFrontmatterDate&&(p=i.sortByObjectKey({arr:p,key:"date",desc:d.sortMenusOrderByDescending,dateSortFromFrontmatter:!0}),i.deepDeleteKey(p,"date")),d.sortMenusOrderNumericallyFromTitle&&(p=i.sortByObjectKey({arr:p,key:"text",desc:d.sortMenusOrderByDescending,numerically:!0})),d.sortMenusOrderNumericallyFromLink&&(p=i.sortByObjectKey({arr:p,key:"link",desc:d.sortMenusOrderByDescending,numerically:!0})),d.sortFolderTo&&(p=i.sortByFileTypes(p,d.sortFolderTo)),p}static getValueFromFrontmatter(t,r,o){try{const o=e(t,"utf-8"),{data:n}=l(o);if(n?.[r])return n[r];const a=o.split("\n");let s=!1;for(let e=0,t=a.length;e]*>/g,(e=>(o.push(e),""))),a=a.replace(/^(#+.*)$/gm,(e=>(n.push(e),""))),r&&!e.keepMarkdownSyntaxFromTitle&&(a=a.replace(/\*{1,2}([^*]+?)\*{1,2}/g,"$1"),a=a.replace(/_{1,2}([^_]+?)_{1,2}/g,"$1"),a=a.replace(/~{1,2}([^~]+?)~{1,2}/g,"$1"),a=a.replace(/`{1,3}([^`]+?)`{1,3}/g,"$1")),e.hyphenToSpace&&(a=a.replace(/-/g," ")),e.underscoreToSpace&&(a=a.replace(/_/g," ")),e.capitalizeEachWords){let e="";for(let t=0;t(l+=1,n[l]))),a=a.replace(new RegExp("","g"),(()=>(s+=1,o[s]))),a}static getTitleFromMd(t,r,o,n,a){if(n)return i.formatTitle(o,t);if(o.useTitleFromFrontmatter){let e=i.getValueFromFrontmatter(r,o.frontmatterTitleFieldName||"title",void 0);if(e||(e=i.getValueFromFrontmatter(r,"title",void 0)),e)return a?.(),i.formatTitle(o,e)}if(o.useTitleFromFileHeading)try{const t=e(r,"utf-8").split("\n");for(let e=0,r=t.length;e0?`${e[1]||""}${e[2]||""}${e[4]||""}`:""}return a?.(),i.formatTitle(o,r,!0)}}}catch{return"Unknown"}return i.formatTitle(o,t.replace(/\.md$/,""))}static sortByFileTypes(e,t){for(let r=0;rObject.hasOwn(e,"items"))),o=e.filter((e=>!Object.hasOwn(e,"items")));return"top"===t?[...r,...o]:[...o,...r]}static sortByObjectKey(e){for(let t=0;tnew Date(t[e.key]).valueOf()-new Date(r[e.key]).valueOf())),e.desc&&(r=r.reverse());else if(e.dateSortFromTextWithPrefix){const t=/^[0-9]{4}-[0-9]{2}-[0-9]{2}/g;r=e.arr.sort(((r,o)=>{const n=r[e.key].split(t)?.[0],a=o[e.key].split(t)?.[0];return new Date(n).valueOf()-new Date(a).valueOf()})),e.desc&&(r=r.reverse())}else r=e.arr.sort(((r,o)=>{const n=t.compare(r[e.key],o[e.key]);return e.desc?-n:n}));return r}static deepDeleteKey(e,t){"object"==typeof e&&null!==e&&(Object.hasOwn(e,t)&&delete e[t],Object.keys(e).forEach((r=>{"object"==typeof e[r]&&i.deepDeleteKey(e[r],t)})))}static removePrefixFromTitleAndLink(e,t){const r=e.length;for(let o=0;o=t}}export{i as VitePressSidebar};export const{generateSidebar:generateSidebar}=i; +\ No newline at end of file ++import{readFileSync as e,readdirSync as t,statSync as r,existsSync as o}from"fs";import{join as n,resolve as a}from"path";import l from"gray-matter";import{globSync as s}from"glob";export default class i{static generateSidebar(e){const t={},r=Array.isArray(e);let o,a,l=!1;if(arguments.length>1)throw new Error("You must pass 1 argument, see the documentation for details.");o=void 0===e?[{}]:Array.isArray(e)?e:[e];for(let e=0;e0){const e=c.filter((e=>-1!==d.manualSortFileNameByPriority?.indexOf(e))),t=c.filter((e=>-1===d.manualSortFileNameByPriority?.indexOf(e)));e.sort(((e,t)=>d.manualSortFileNameByPriority.indexOf(e)-d.manualSortFileNameByPriority.indexOf(t))),c=[...e,...t]}let p=c.map((t=>{const s=a(n,t);let c=`${l}/${t}`.replace(/\/{2}/,"/").replace(/(index)?\.md$/,"");if(d.documentRootPath&&c.startsWith(d.documentRootPath)&&(c=c.replace(new RegExp(`^${d.documentRootPath}`,"g"),""),d.scanStartPath||d.resolvePath?(c=c.replace(/^\//g,""),d.scanStartPath&&(c=c.replace(new RegExp(`^${d.scanStartPath}`,"g"),"")),c=c.replace(/^\/(?!$)/g,""),"/"===c&&(c="index.md")):c.startsWith("/")||(c=`/${c}`)),/\.vitepress/.test(s))return null;if(/node_modules/.test(s))return null;if(1===e&&"index.md"===t&&!d.includeRootIndexFile)return null;if(1!==e&&"index.md"===t&&!d.includeFolderIndexFile)return null;if(!d.includeDotFiles&&/^\./.test(t))return null;if(!m.includes(t))return null;if(r(s).isDirectory()){if(d.excludeFolders?.includes(t))return null;let r,n=i.generateSidebarItem(e+1,s,c,t,d)||[],l=!1,u=i.getTitleFromMd(t,s,d,!0,(()=>{l=!0})),m=s,p=!1;const F=`${s}/index.md`,y=n.find((e=>e.text===t));return d.convertSameNameSubFileToGroupIndexPage&&y&&(m=a(s,`${y.text}.md`),u=i.getTitleFromMd(t,m,d,!1,(()=>{l=!0})),r=d.folderLinkNotIncludesFileName?`${c}/`:y.link,n=n.filter((e=>e.text!==t))),o(F)&&(d.includeFolderIndexFile&&(p=!0),d.useFolderLinkFromIndexFile&&(p=!0,m=F,r=`${c}/index.md`),d.useFolderTitleFromIndexFile&&!l&&(p=!0,m=F,u=i.getTitleFromMd("index",m,d,!1))),r&&!1!==d.includeEmptyFolder||d.includeEmptyFolder||n.length>0||p?{text:u,...r?{link:r}:{},...n.length>0?{items:n}:{},...null===d.collapsed||void 0===d.collapsed||n.length<1?{}:{collapsed:e>=d.collapseDepth&&d.collapsed},...d.sortMenusByFrontmatterOrder?{order:i.getOrderFromFrontmatter(m,d.frontmatterOrderDefaultValue)}:{},...d.sortMenusByFrontmatterDate?{date:i.getDateFromFrontmatter(s)}:{}}:null}if(s.endsWith(".md")){if(d.excludeFiles?.includes(t)||i.getExcludeFromFrontmatter(s,d.excludeFilesByFrontmatterFieldName))return null;let e;const r=t.replace(/\.md$/,"");return e=d.convertSameNameSubFileToGroupIndexPage&&u===r?r:i.getTitleFromMd(t,s,d,!1),{text:e,link:c,...d.sortMenusByFrontmatterOrder?{order:i.getOrderFromFrontmatter(s,d.frontmatterOrderDefaultValue)}:{},...d.sortMenusByFrontmatterDate?{date:i.getDateFromFrontmatter(s)}:{}}}return null})).filter((e=>null!==e));return d.sortMenusByName&&(p=i.sortByObjectKey({arr:p,key:"text",desc:d.sortMenusOrderByDescending})),d.sortMenusByFileDatePrefix&&(p=i.sortByObjectKey({arr:p,key:"text",desc:d.sortMenusOrderByDescending,dateSortFromTextWithPrefix:!0,datePrefixSeparator:d.prefixSeparator})),d.sortMenusByFrontmatterOrder&&(p=i.sortByObjectKey({arr:p,key:"order",desc:d.sortMenusOrderByDescending,numerically:!0}),i.deepDeleteKey(p,"order")),d.sortMenusByFrontmatterDate&&(p=i.sortByObjectKey({arr:p,key:"date",desc:d.sortMenusOrderByDescending,dateSortFromFrontmatter:!0}),i.deepDeleteKey(p,"date")),d.sortMenusOrderNumericallyFromTitle&&(p=i.sortByObjectKey({arr:p,key:"text",desc:d.sortMenusOrderByDescending,numerically:!0})),d.sortMenusOrderNumericallyFromLink&&(p=i.sortByObjectKey({arr:p,key:"link",desc:d.sortMenusOrderByDescending,numerically:!0})),d.sortFolderTo&&(p=i.sortByFileTypes(p,d.sortFolderTo)),p}static getValueFromFrontmatter(t,r,o){try{const o=e(t,"utf-8"),{data:n}=l(o);if(n?.[r])return n[r];const a=o.split("\n");let s=!1;for(let e=0,t=a.length;e]*>/g,(e=>(o.push(e),""))),a=a.replace(/^(#+.*)$/gm,(e=>(n.push(e),""))),r&&!e.keepMarkdownSyntaxFromTitle&&(a=a.replace(/\*{1,2}([^*]+?)\*{1,2}/g,"$1"),a=a.replace(/_{1,2}([^_]+?)_{1,2}/g,"$1"),a=a.replace(/~{1,2}([^~]+?)~{1,2}/g,"$1"),a=a.replace(/`{1,3}([^`]+?)`{1,3}/g,"$1")),e.hyphenToSpace&&(a=a.replace(/-/g," ")),e.underscoreToSpace&&(a=a.replace(/_/g," ")),e.capitalizeEachWords){let e="";for(let t=0;t(l+=1,n[l]))),a=a.replace(new RegExp("","g"),(()=>(s+=1,o[s]))),a}static getTitleFromMd(t,r,o,n,a){if(n)return i.formatTitle(o,t);if(o.useTitleFromFrontmatter){let e=i.getValueFromFrontmatter(r,o.frontmatterTitleFieldName||"title",void 0);if(e||(e=i.getValueFromFrontmatter(r,"title",void 0)),e)return a?.(),i.formatTitle(o,e)}if(o.useTitleFromFileHeading)try{const t=e(r,"utf-8").split("\n");for(let e=0,r=t.length;e0?`${e[1]||""}${e[2]||""}${e[4]||""}`:""}return a?.(),i.formatTitle(o,r,!0)}}}catch{return"Unknown"}return i.formatTitle(o,t.replace(/\.md$/,""))}static sortByFileTypes(e,t){for(let r=0;rObject.hasOwn(e,"items"))),o=e.filter((e=>!Object.hasOwn(e,"items")));return"top"===t?[...r,...o]:[...o,...r]}static sortByObjectKey(e){for(let t=0;tnew Date(t[e.key]).valueOf()-new Date(r[e.key]).valueOf())),e.desc&&(r=r.reverse());else if(e.dateSortFromTextWithPrefix){const t=/^[0-9]{4}-[0-9]{2}-[0-9]{2}/g;r=e.arr.sort(((r,o)=>{const n=r[e.key].split(t)?.[0],a=o[e.key].split(t)?.[0];return new Date(n).valueOf()-new Date(a).valueOf()})),e.desc&&(r=r.reverse())}else r=e.arr.sort(((r,o)=>{const n=t.compare(r[e.key],o[e.key]);return e.desc?-n:n}));return r}static deepDeleteKey(e,t){"object"==typeof e&&null!==e&&(Object.hasOwn(e,t)&&delete e[t],Object.keys(e).forEach((r=>{"object"==typeof e[r]&&i.deepDeleteKey(e[r],t)})))}static removePrefixFromTitleAndLink(e,t){const r=e.length;for(let o=0;o=t}}export{i as VitePressSidebar};export const{generateSidebar:generateSidebar}=i; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e970dea..38ca6a2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,11 @@ settings: overrides: is-core-module: npm:@nolyfill/is-core-module@^1 +patchedDependencies: + vitepress-sidebar: + hash: ofcji3izwccjcyyjrhgyx26c5i + path: patches/vitepress-sidebar.patch + importers: .: @@ -58,7 +63,7 @@ importers: version: 1.3.4(@algolia/client-search@5.5.3)(@types/node@20.16.5)(less@4.2.0)(postcss@8.4.47)(search-insights@2.17.2)(typescript@5.6.2) vitepress-sidebar: specifier: ^1.23.2 - version: 1.27.0 + version: 1.27.0(patch_hash=ofcji3izwccjcyyjrhgyx26c5i) vue: specifier: ^3.4.30 version: 3.5.6(typescript@5.6.2) @@ -7200,7 +7205,7 @@ snapshots: fsevents: 2.3.3 less: 4.2.0 - vitepress-sidebar@1.27.0: + vitepress-sidebar@1.27.0(patch_hash=ofcji3izwccjcyyjrhgyx26c5i): dependencies: glob: 10.4.5 gray-matter: 4.0.3