Fix basePath

This commit is contained in:
John Hildenbiddle 2020-10-24 20:44:24 -05:00
parent febe7f8ee1
commit b6d54072b3
2 changed files with 23 additions and 11 deletions

View File

@ -77,15 +77,27 @@ async function docsifyInit(options = {}) {
loadSidebar: Boolean(settings.markdown.sidebar),
};
const updateBasePath = config => {
config.basePath = new URL(config.basePath, TEST_HOST).href;
};
// Config as function
if (typeof options.config === 'function') {
return function(vm) {
return { ...sharedConfig, ...options.config(vm) };
const config = { ...sharedConfig, ...options.config(vm) };
updateBasePath(config);
return config;
};
}
// Config as object
else {
return { ...sharedConfig, ...options.config };
const config = { ...sharedConfig, ...options.config };
updateBasePath(config);
return config;
}
},
get markdown() {
@ -101,10 +113,10 @@ async function docsifyInit(options = {}) {
get routes() {
const helperRoutes = {
[settings.testURL]: stripIndent`${settings.html}`,
['/README.md']: settings.markdown.homepage,
['/_coverpage.md']: settings.markdown.coverpage,
['/_navbar.md']: settings.markdown.navbar,
['/_sidebar.md']: settings.markdown.sidebar,
['README.md']: settings.markdown.homepage,
['_coverpage.md']: settings.markdown.coverpage,
['_navbar.md']: settings.markdown.navbar,
['_sidebar.md']: settings.markdown.sidebar,
};
const finalRoutes = Object.fromEntries(
@ -116,7 +128,7 @@ async function docsifyInit(options = {}) {
.filter(([url, responseText]) => url && responseText)
.map(([url, responseText]) => [
// Convert relative to absolute URL
new URL(url, TEST_HOST).href,
new URL(url, settings.config.basePath).href,
// Strip indentation from responseText
stripIndent`${responseText}`,
])

View File

@ -10,7 +10,7 @@ describe('Example Tests', function() {
test('Docsify /docs/ site using docsifyInit()', async () => {
await docsifyInit({
config: {
basePath: `${TEST_HOST}/docs`,
basePath: '/docs/',
},
// _logHTML: true,
});
@ -51,12 +51,12 @@ describe('Example Tests', function() {
`,
},
routes: {
'/test.md': `
'test.md': `
# Test Page
This is a custom route.
`,
'/data-test-scripturls.js': `
'data-test-scripturls.js': `
document.body.setAttribute('data-test-scripturls', 'pass');
`,
},
@ -65,7 +65,7 @@ describe('Example Tests', function() {
`,
scriptURLs: [
// docsifyInit() route
'/data-test-scripturls.js',
'data-test-scripturls.js',
// Server route
'/lib/plugins/search.min.js',
],