mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-02 03:59:19 +08:00
Support functions in docsify configuration
This commit is contained in:
parent
cd8f2d3efc
commit
ecd053b25c
@ -197,9 +197,21 @@ async function docsifyInit(options = {}) {
|
||||
if (isJSDOM) {
|
||||
window.$docsify = settings.config;
|
||||
} else if (isPlaywright) {
|
||||
// Convert config functions to strings
|
||||
const configString = JSON.stringify(settings.config, (key, val) =>
|
||||
typeof val === 'function' ? `__FN__${val.toString()}` : val
|
||||
);
|
||||
|
||||
await page.evaluate(config => {
|
||||
window.$docsify = config;
|
||||
}, settings.config);
|
||||
// Restore config functions from strings
|
||||
const configObj = JSON.parse(config, (key, val) =>
|
||||
/^__FN__/.test(val)
|
||||
? new Function(`return ${val.split('__FN__')[1]}`)()
|
||||
: val
|
||||
);
|
||||
|
||||
window.$docsify = configObj;
|
||||
}, configString);
|
||||
}
|
||||
|
||||
// Style URLs
|
||||
|
Loading…
Reference in New Issue
Block a user