Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/fetch/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@ export function Fetch(Base) {
path = getParentPath(path);

if (!path) {
next('');
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/render/compiler.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ export class Compiler {
let html = '';

// compile sidebar from _sidebar.md
if (text) {
if (typeof text === 'string') {
return this.compile(text);
}
// compile sidebar from content's headings toc
Expand Down
83 changes: 83 additions & 0 deletions test/e2e/plugins.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,6 +79,89 @@ test.describe('Plugins', () => {
expect(consoleMsgs).toEqual(expectedMsgs);
});

test('ready runs once when the initial sidebar is missing', async ({
page,
}) => {
await page.route('_sidebar.md', route => route.fulfill({ status: 404 }));

await docsifyInit({
config: {
loadSidebar: true,
name: 'Docsify',
nameLink: '#/',
plugins: [
function (hook) {
window.hookCalls = [];

hook.doneEach(() => {
window.hookCalls.push('doneEach');
});

hook.ready(() => {
window.hookCalls.push('ready');
document
.querySelector('.sidebar-nav')
.addEventListener('click', event => {
const groupTitle = event.target.closest(
'.sidebar-nav > ul > li > p',
);

groupTitle?.parentElement.classList.toggle('plugin-collapse');
});
});
},
],
},
markdown: {
homepage: `
# Home

[Section](/section/)
`,
},
routes: {
'/section/README.md': '# Section',
'/section/_sidebar.md': `
- Group
- [Page](page)
`,
},
});

await expect
.poll(() => page.evaluate(() => window.hookCalls))
.toEqual(['doneEach', 'ready']);
await expect(page.locator('.sidebar-nav')).toBeEmpty();

await page.locator('a[href="#/section/"]').click();

const group = page.locator('.sidebar-nav > ul > li').first();
await expect(group.locator(':scope > p')).toHaveText('Group');

await group.locator(':scope > p').click();
await expect(group).toHaveClass(/plugin-collapse/);
await expect
.poll(() => page.evaluate(() => window.hookCalls))
.toEqual(['doneEach', 'ready', 'doneEach']);

await page.locator('.app-name-link').click();

await expect(page.locator('#main h1')).toHaveText('Home');
await expect(page.locator('.sidebar-nav')).toBeEmpty();
await expect
.poll(() => page.evaluate(() => window.hookCalls))
.toEqual(['doneEach', 'ready', 'doneEach', 'doneEach']);

await page.locator('a[href="#/section/"]').click();

await expect(group.locator(':scope > p')).toHaveText('Group');
await group.locator(':scope > p').click();
await expect(group).toHaveClass(/plugin-collapse/);
await expect
.poll(() => page.evaluate(() => window.hookCalls))
.toEqual(['doneEach', 'ready', 'doneEach', 'doneEach', 'doneEach']);
});

test.describe('beforeEach()', () => {
test('return value', async ({ page }) => {
await docsifyInit({
Expand Down