Skip to content
Closed
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
13 changes: 13 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,19 @@ window.$docsify = {
};
```

## rightSidebar

- Type : `Boolean`
- Default: `false`

Position the sidebar on the right side of the page instead of the left.

```js
window.$docsify = {
rightSidebar: true,
};
```

## routerMode

Configure the URL format that the paths of your site will use.
Expand Down
1 change: 1 addition & 0 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const defaultDocsifyConfig = () => ({
relativePath: false,
repo: /** @type {string} */ (''),
requestHeaders: /** @type {Record<string, string>} */ ({}),
rightSidebar: false,
routerMode: /** @type {'hash' | 'history'} */ 'hash',
routes: /** @type {Record<string, string | RouteHandler>} */ ({}),
skipLink: /** @type {false | string | Record<string, string>} */ (
Expand Down
3 changes: 3 additions & 0 deletions src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ export function Render(Base) {
initRender() {
const config = this.config;

// Position the sidebar on the right instead of the left
dom.body.classList.toggle('right-sidebar', !!config.rightSidebar);

// Init markdown compiler
this.compiler = new Compiler(config, this.router);
window.__current_docsify_compiler__ = this.compiler;
Expand Down
35 changes: 35 additions & 0 deletions src/themes/shared/_sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,41 @@
}
}

/* Right Sidebar */
/* ========================================================================== */
body.right-sidebar {
.sidebar {
left: auto;
right: 0;
translate: var(--sidebar-width);
border-right: 0;
border-left: 1px solid var(--sidebar-border-color);
}

.sidebar-toggle {
left: auto;
right: 0;
}

.sidebar-toggle-button {
border-radius: var(--border-radius) 0 0 var(--border-radius);
}

&:has(.sidebar.show) {
main > .content {
right: var(--sidebar-width);
}

.app-nav {
right: var(--sidebar-width);
}

.sidebar-toggle {
translate: calc(0px - var(--sidebar-width));
}
}
}

.sidebar-toggle-button {
display: flex;
flex-direction: column;
Expand Down
27 changes: 27 additions & 0 deletions test/integration/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,30 @@ describe('Test sidebar render toc structure', function () {
expect(sidebarText).not.toContain('Quoted Title Without Space');
});
});

describe('Configuration: rightSidebar', () => {
test('rightSidebar=true adds the right-sidebar class to <body>', async () => {
await docsifyInit({
config: {
rightSidebar: true,
},
markdown: {
homepage: '# Hello World',
},
waitForSelector: '.sidebar',
});

expect(document.body.classList.contains('right-sidebar')).toBe(true);
});

test('rightSidebar=false (default) does not add the right-sidebar class', async () => {
await docsifyInit({
markdown: {
homepage: '# Hello World',
},
waitForSelector: '.sidebar',
});

expect(document.body.classList.contains('right-sidebar')).toBe(false);
});
});