Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6d5407

Browse files
committed
Fix basePath
1 parent febe7f8 commit b6d5407

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

test/helpers/docsify-init.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,27 @@ async function docsifyInit(options = {}) {
7777
loadSidebar: Boolean(settings.markdown.sidebar),
7878
};
7979

80+
const updateBasePath = config => {
81+
config.basePath = new URL(config.basePath, TEST_HOST).href;
82+
};
83+
8084
// Config as function
8185
if (typeof options.config === 'function') {
8286
return function(vm) {
83-
return { ...sharedConfig, ...options.config(vm) };
87+
const config = { ...sharedConfig, ...options.config(vm) };
88+
89+
updateBasePath(config);
90+
91+
return config;
8492
};
8593
}
8694
// Config as object
8795
else {
88-
return { ...sharedConfig, ...options.config };
96+
const config = { ...sharedConfig, ...options.config };
97+
98+
updateBasePath(config);
99+
100+
return config;
89101
}
90102
},
91103
get markdown() {
@@ -101,10 +113,10 @@ async function docsifyInit(options = {}) {
101113
get routes() {
102114
const helperRoutes = {
103115
[settings.testURL]: stripIndent`${settings.html}`,
104-
['/README.md']: settings.markdown.homepage,
105-
['/_coverpage.md']: settings.markdown.coverpage,
106-
['/_navbar.md']: settings.markdown.navbar,
107-
['/_sidebar.md']: settings.markdown.sidebar,
116+
['README.md']: settings.markdown.homepage,
117+
['_coverpage.md']: settings.markdown.coverpage,
118+
['_navbar.md']: settings.markdown.navbar,
119+
['_sidebar.md']: settings.markdown.sidebar,
108120
};
109121

110122
const finalRoutes = Object.fromEntries(
@@ -116,7 +128,7 @@ async function docsifyInit(options = {}) {
116128
.filter(([url, responseText]) => url && responseText)
117129
.map(([url, responseText]) => [
118130
// Convert relative to absolute URL
119-
new URL(url, TEST_HOST).href,
131+
new URL(url, settings.config.basePath).href,
120132
// Strip indentation from responseText
121133
stripIndent`${responseText}`,
122134
])

test/integration/example.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Example Tests', function() {
1010
test('Docsify /docs/ site using docsifyInit()', async () => {
1111
await docsifyInit({
1212
config: {
13-
basePath: `${TEST_HOST}/docs`,
13+
basePath: '/docs/',
1414
},
1515
// _logHTML: true,
1616
});
@@ -51,12 +51,12 @@ describe('Example Tests', function() {
5151
`,
5252
},
5353
routes: {
54-
'/test.md': `
54+
'test.md': `
5555
# Test Page
5656
5757
This is a custom route.
5858
`,
59-
'/data-test-scripturls.js': `
59+
'data-test-scripturls.js': `
6060
document.body.setAttribute('data-test-scripturls', 'pass');
6161
`,
6262
},
@@ -65,7 +65,7 @@ describe('Example Tests', function() {
6565
`,
6666
scriptURLs: [
6767
// docsifyInit() route
68-
'/data-test-scripturls.js',
68+
'data-test-scripturls.js',
6969
// Server route
7070
'/lib/plugins/search.min.js',
7171
],

0 commit comments

Comments
 (0)