UNPKG

@soyvolon/docsify-file-name-replace

Version:

Docsify plugin to modify certain paths to replace strings.

2 lines (1 loc) 730 B
"use strict";const p=e=>r=>r.beforeEach((l,a)=>{e.prefix||(e.prefix="r");let t=e.methods,i=`\\{\\{${e.prefix}\\:(.*)\\}\\:?(.*)?\\}`,c=new RegExp(i,"gi"),f=l.matchAll(c);u(l,f,t).then(o=>{a(o)})});async function u(e,r,l){let a=0;for(const t of r)try{let i=t.index+a,c=t[0].length,f=t[1],o=await fetch(f);if(!o.ok)continue;let n=await o.text();try{let s=JSON.stringify(JSON.parse(n));t[2]&&(s=l[t[2]](s)),a+=s.length-c,e=e.slice(0,i)+s+e.slice(i+c)}catch{t[2]&&(n=l[t[2]](n)),a+=n.length-c,e=e.slice(0,i)+n+e.slice(i+c)}}catch(i){console.log("Failed to replace file path: "+i)}return e}const g=window.$docsify||{},d={fileNameReplacePlugin:g.fileNameReplacePlugin??{}};g.plugins=[].concat(g.plugins||[],p(d.fileNameReplacePlugin));