UNPKG

@soyvolon/docsify-file-name-replace

Version:

Docsify plugin to modify certain paths to replace strings.

34 lines (33 loc) 985 B
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); d(l, f, t).then((s) => { a(s); }); }); async function d(e, r, l) { let a = 0; for (const t of r) try { let i = t.index + a, c = t[0].length, f = t[1], s = await fetch(f); if (!s.ok) continue; let n = await s.text(); try { let o = JSON.stringify(JSON.parse(n)); t[2] && (o = l[t[2]](o)), a += o.length - c, e = e.slice(0, i) + o + 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 || {}, u = { fileNameReplacePlugin: g.fileNameReplacePlugin ?? {} }; g.plugins = [].concat( g.plugins || [], p(u.fileNameReplacePlugin) );