@huyikai/vitepress-helper
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,2 @@ | ||
import e from"fs-extra";import t from"globby";import r from"gray-matter";import{v4 as i}from"uuid";import{treeToArray as l,arrayToTree as n}from"tree-conver";const o=(e,t)=>e.frontMatter.date<t.frontMatter.date?1:-1;var a=async l=>{const{directory:n}=l,a=await t([`${n}/**/**.md`],{ignore:["node_modules","README.md","packages"]});let s=await Promise.all(a.map((async t=>{const l=await e.readFile(t,"utf-8"),n=r(l);return{frontMatter:n.data,link:t,content:n.content.replace(/[^a-zA-Z0-9._ ]+/g,"").toLowerCase(),uuid:i()}})));return s=s.filter((e=>!e.frontMatter.page)),s.sort(o),s};const s=(e,t)=>e.sort(((e,r)=>e[t].localeCompare(r.link)));var d=e=>{const{pages:t,directory:r}=e;return(e=>{const t=e.map((e=>{const{link:t,frontMatter:l}=e,n=t.split(`${r}/`)[1].split("/"),o=n.slice(0,-1).join("/"),a=l?.title||n.slice(-1).join("").replace(".md",""),s=n.length-1;return{...e,id:i(),text:a,link:n.join("/"),level:s,dir:o}})),o=t.filter((e=>e.level>0)),a=t.filter((e=>0===e.level)),d=(e=>{const t={children:[]};return e.forEach((e=>{let r=t;e.forEach(((t,l)=>{let n=r.children.find((e=>e.text===t));n||(n={text:t,id:i(),dir:e.slice(0,l+1).join("/"),children:[]},r.children.push(n)),r=n}))})),t.children})(o.map((e=>e.link.split("/").slice(0,-1)))),c=l(d);o.forEach((e=>{c.forEach((t=>{t.dir===e.dir&&(e.parentId=t.id)}))}));const p=[...s(c,"dir"),...s(o,"link")].map((e=>({text:e.text,link:e.link,id:e.id,parentId:e.parentId}))),f=n(p,{idKey:"id",pidKey:"parentId",childrenKey:"items"});return[...s(a.map((e=>"index.md"===e.link?{...e,text:"Home"}:e)),"text"),...f]})(t.filter((e=>e.link.includes(`${r}/`))))},c=e=>{const{pages:t,directory:r,collapsible:i}=e;let l=[],n=[];for(let e of t){let t=e.link.replace(`${r}/`,"").split("/").filter(((e,t)=>e.indexOf(".md")<0&&t<2)).join("/");t.indexOf("/")>=0&&l.push(t);let i=e.link.replace(`${r}/`,"").split("/");for(let e=0,t=i.length;e<t;e++){let t=i[e],r={text:t.replace(".md",""),key:t,parentKey:e>0?i[e-1]:void 0,link:`/${i.join("/")}`};n.push(r)}}function o(e,t=""){const r=new Map;return e.filter((e=>!r.has(t?e[t]:e)&&r.set(t?e[t]:e,1)))}l=l.filter((e=>!["","/"].includes(e))),l.sort(),n=n.sort((function(e,t){var r=e.text,i=t.text;return r<i?-1:r>i?1:0})),l=o(l);let a={};for(let e of l)a[e]=[{text:e.split("/").filter((e=>e)).splice(-1,1)[0],key:e.split("/").filter((e=>e)).splice(-1,1)[0],parentKey:void 0}];for(let e in a)s(a[e][0]);function s(e){let t=n.filter((t=>e.key===t.parentKey));if(t=o(t,"key"),t){for(let e of t)s(e);!(e.hasOwnProperty("link")&&e.key.indexOf(".md")>=0)&&delete e.link,e.items=t,e.collapsible=i,e.collapsed=null}}return a},p=async(e={directory:"docs",collapsible:!0})=>{const t=await a(e),r={pages:t,...e};return{nav:d(r),sidebar:c(r),pages:t}};export{p as default,p as init,d as nav,a as pages,c as sidebar}; | ||
import t from"fs-extra";import e from"globby";import r from"gray-matter";import{v4 as i}from"uuid";import{treeToArray as n,arrayToTree as o}from"tree-conver";const a=(t,e)=>t.frontMatter.date<e.frontMatter.date?1:-1;var l=async n=>{const{directory:o}=n,l=await e([`${o}/**/**.md`],{ignore:["node_modules","README.md","packages"]});let d=await Promise.all(l.map((async e=>{const n=await t.readFile(e,"utf-8"),o=r(n);return{frontMatter:o.data,link:e,content:o.content.replace(/[^a-zA-Z0-9._ ]+/g,"").toLowerCase(),uuid:i()}})));return d=d.filter((t=>!t.frontMatter.page||t.link.includes(`${o}/`))),d.sort(a),d};const d=(t,e)=>t.map((t=>{const{link:r,frontMatter:n}=t,o=r.split(`${e}/`)[1].split("/"),a=o.slice(0,-1).join("/"),l=n?.title||o.slice(-1).join("").replace(".md",""),d=o.length-1;return{...t,id:i(),text:l,link:o.join("/"),level:d,dir:a}})),s=t=>{const{pages:e,directory:r,transformItem:a}=t,l=d(e,r).filter((t=>t.level>0)),s=(t=>{const e={children:[]};return t.forEach((t=>{let r=e;t.forEach(((e,n)=>{let o=r.children.find((t=>t.text===e));o||(o={text:e,id:i(),dir:t.slice(0,n+1).join("/"),children:[]},r.children.push(o)),r=o}))})),e.children})(l.map((t=>t.link.split("/").slice(0,-1)))),p=n(s);l.forEach((t=>{p.forEach((e=>{e.dir===t.dir&&(t.parentId=e.id)}))}));const m=[...c(p,"dir"),...c(l,"link")].map((t=>a(t)));return o(m,{idKey:"id",pidKey:"parentId",childrenKey:"items"})},c=(t,e)=>{if(e){const r=(t,r)=>t[e].localeCompare(r.link);return t.sort(r)}return t.sort()};var p=t=>{const{pages:e,directory:r}=t,i=d(e,r).filter((t=>0===t.level));return[...c(i.map((t=>({...t,text:"index.md"===t.link?"Home":t.text,link:`/${t.link}`}))),"text"),...s({pages:e,directory:r,transformItem:t=>({text:t.text,link:t.link?`/${t.link}`:void 0,id:t.id,parentId:t.parentId})})]},m=t=>{const{pages:e,directory:r,collapsible:i}=t;return s({pages:e,directory:r,transformItem:t=>{const{id:e,text:r,link:n,dir:o,parentId:a}=t;return{text:r,id:e,dir:o,parentId:a,collapsed:!(!n&&!0===i)&&void 0,link:n?`/${n}`:void 0}}}).reduce(((t,e)=>{const r=`/${e.text}/`;return t[r]||(t[r]=[]),t[r].push({text:e.text,collapsed:!0!==i&&void 0,items:[...e.items]}),t}),{})},f=async(t={directory:"docs",collapsible:!0})=>{const e=await l(t),r={pages:e,...t};return{nav:p(r),sidebar:m(r),pages:e}};export{f as default,f as init,p as nav,l as pages,m as sidebar}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -52,3 +52,3 @@ { | ||
"types": "lib/types/index.d.ts", | ||
"version": "0.0.2" | ||
"version": "0.0.3" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
69
17049