From 9c37c5cd224540a9c001cf480e6d8a45bb73c9bc Mon Sep 17 00:00:00 2001 From: Koy Date: Tue, 13 Oct 2020 19:20:54 +0800 Subject: [PATCH 1/8] [refactor] hideSidebar. --- src/core/config.js | 1 + src/core/fetch/index.js | 27 ++++++++++++++++++++------- src/core/render/index.js | 15 ++------------- src/core/render/tpl.js | 3 ++- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/core/config.js b/src/core/config.js index 2d23f5db2..1429b4977 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -11,6 +11,7 @@ export default function(vm) { subMaxLevel: 0, loadSidebar: null, loadNavbar: null, + hideSidebar: false, homepage: 'README.md', coverpage: '', basePath: '', diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index 1853a0297..dde21afe9 100644 --- a/src/core/fetch/index.js +++ b/src/core/fetch/index.js @@ -85,8 +85,11 @@ export function fetchMixin(proto) { return path404; }; - proto._loadSideAndNav = function(path, qs, loadSidebar, cb) { + proto._loadSideAndNav = function(path, qs, loadSidebar, hideSidebar, cb) { return () => { + if (hideSidebar) { + return; + } if (!loadSidebar) { return cb(); } @@ -104,7 +107,12 @@ export function fetchMixin(proto) { proto._fetch = function(cb = noop) { const { path, query } = this.route; const qs = stringifyQuery(query, ['id']); - const { loadNavbar, requestHeaders, loadSidebar } = this.config; + const { + loadNavbar, + requestHeaders, + loadSidebar, + hideSidebar, + } = this.config; // Abort last request const file = this.router.getFile(path); @@ -120,7 +128,7 @@ export function fetchMixin(proto) { this._renderMain( text, opt, - this._loadSideAndNav(path, qs, loadSidebar, cb) + this._loadSideAndNav(path, qs, loadSidebar, hideSidebar, cb) ), _ => { this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb); @@ -197,7 +205,12 @@ export function fetchMixin(proto) { }; proto._fetchFallbackPage = function(path, qs, cb = noop) { - const { requestHeaders, fallbackLanguages, loadSidebar } = this.config; + const { + requestHeaders, + fallbackLanguages, + loadSidebar, + hideSidebar, + } = this.config; if (!fallbackLanguages) { return false; @@ -219,7 +232,7 @@ export function fetchMixin(proto) { this._renderMain( text, opt, - this._loadSideAndNav(path, qs, loadSidebar, cb) + this._loadSideAndNav(path, qs, loadSidebar, hideSidebar, cb) ), () => this._fetch404(path, qs, cb) ); @@ -255,7 +268,7 @@ export function fetchMixin(proto) { } export function initFetch(vm) { - const { loadSidebar } = vm.config; + const { loadSidebar, hideSidebar } = vm.config; // Server-Side Rendering if (vm.rendered) { @@ -264,7 +277,7 @@ export function initFetch(vm) { activeEl.parentNode.innerHTML += window.__SUB_SIDEBAR__; } - vm._bindEventOnRendered(activeEl); + !hideSidebar && vm._bindEventOnRendered(activeEl); vm.$resetEvents(); callHook(vm, 'doneEach'); callHook(vm, 'ready'); diff --git a/src/core/render/index.js b/src/core/render/index.js index 42e62ba96..0984fab58 100644 --- a/src/core/render/index.js +++ b/src/core/render/index.js @@ -48,7 +48,7 @@ function renderMain(html) { this._renderTo('.markdown-section', html); // Render sidebar with the TOC - !this.config.loadSidebar && this._renderSidebar(); + !this.config.loadSidebar && !this.config.hideSidebar && this._renderSidebar(); // Execute markdown