From b265fdd68a57c48126a5199241e3ebad0335c1ac Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 10 Feb 2018 14:35:35 +0800 Subject: [PATCH] feat(cover): add onlyCover option, close #382 --- src/core/fetch/index.js | 18 ++++++++++++++---- src/core/render/index.js | 1 + src/themes/basic/_layout.css | 6 +++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index 3594f5a6d..4e898908d 100644 --- a/src/core/fetch/index.js +++ b/src/core/fetch/index.js @@ -85,6 +85,7 @@ export function fetchMixin (proto) { path = cover === true ? '_coverpage.md' : cover } + this.coverEnable = !!path if (path) { path = this.router.getFile(root + path) this.coverIsHTML = /\.html$/g.test(path) @@ -98,12 +99,21 @@ export function fetchMixin (proto) { } proto.$fetch = function (cb = noop) { - this._fetchCover() - this._fetch(result => { - this.$resetEvents() + const done = () => { callHook(this, 'doneEach') cb() - }) + } + + this._fetchCover() + + if (this.coverEnable && this.config.onlyCover) { + done() + } else { + this._fetch(result => { + this.$resetEvents() + done() + }) + } } } diff --git a/src/core/render/index.js b/src/core/render/index.js index 7dd482302..3fe55b2fb 100644 --- a/src/core/render/index.js +++ b/src/core/render/index.js @@ -38,6 +38,7 @@ function renderMain (html) { html = 'not found' } + dom.toggleClass(dom.getNode('main'), 'add', 'ready') this._renderTo('.markdown-section', html) // Render sidebar with the TOC !this.config.loadSidebar && this._renderSidebar() diff --git a/src/themes/basic/_layout.css b/src/themes/basic/_layout.css index edfae8c1e..ffbf8409c 100644 --- a/src/themes/basic/_layout.css +++ b/src/themes/basic/_layout.css @@ -217,12 +217,16 @@ li input[type='checkbox'] { /* main */ main { - display: block; + display: none; position: relative; size: 100vw 100%; z-index: 0; } +main.ready { + display: block; +} + .anchor { display: inline-block; text-decoration: none;