From 383b976ddd38da269fe5a9e4883ba5dcf6e7eae7 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 24 Dec 2016 11:33:48 +0800 Subject: [PATCH 001/926] Update docs --- docs/README.md | 8 ++++++++ docs/zh-cn.md | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/docs/README.md b/docs/README.md index 8e293e5..8dda6ac 100644 --- a/docs/README.md +++ b/docs/README.md @@ -89,6 +89,14 @@ Code in `404.html` ``` +### Hash router +`404.html` is not SEO friendly, you can replace it use `index.html` and `data-router` [issue#7](https://github.com/QingWei-Li/docsify/issues/7) + +index.html + +```html + +``` ### CDN - UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/) diff --git a/docs/zh-cn.md b/docs/zh-cn.md index 745440a..7897cb1 100644 --- a/docs/zh-cn.md +++ b/docs/zh-cn.md @@ -94,6 +94,15 @@ docsify serve docs ``` +### Hash router +`404.html` 对 SEO 不友好, 你可以用 `index.html` 代替并开启 `hash router` 功能。 [issue#7](https://github.com/QingWei-Li/docsify/issues/7) + +index.html + +```html + +``` + ### CDN - UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/) From 67f9083ff731c03c6e027195cc4b2cba09d338e4 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 24 Dec 2016 19:50:04 +0800 Subject: [PATCH 002/926] Remove 404.html --- README.md | 6 ------ docs/README.md | 23 +++++++---------------- docs/zh-cn.md | 26 +++++++++----------------- 3 files changed, 16 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 6b15d72..70c0e1e 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,6 @@ index.html ``` -Or create a `404.html` and `README.md` into `/docs`. Just remove `data-router` - -```html - -``` - ## CDN - UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/) - jsDelivr [http://www.jsdelivr.com/projects/docsify](http://www.jsdelivr.com/projects/docsify) diff --git a/docs/README.md b/docs/README.md index 8dda6ac..2513e46 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,7 +8,7 @@ mkdir docs && cd docs ``` ### Create entry file -Create a `404.html` file +Create a `index.html` file ```html @@ -20,7 +20,7 @@ Create a `404.html` file
- + ``` @@ -77,27 +77,18 @@ Minified files ## More ### Multiple pages -If you need other pages, directly create the markdown file, such as `guide.md` is `/guide`. +If you need other pages, directly create the markdown file, such as `guide.md` is `/#/guide`. ### Navbar -Code in `404.html` +Code in `index.html` ```html ``` -### Hash router -`404.html` is not SEO friendly, you can replace it use `index.html` and `data-router` [issue#7](https://github.com/QingWei-Li/docsify/issues/7) - -index.html - -```html - -``` - ### CDN - UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/) - jsDelivr [http://www.jsdelivr.com/projects/docsify](http://www.jsdelivr.com/projects/docsify) @@ -242,7 +233,7 @@ If you write a sub level list, it will generate a dropdown list. #### router -Hash router. You can replace `404.html` with `index.html`. +Hash router. ```html diff --git a/docs/zh-cn.md b/docs/zh-cn.md index 7897cb1..bf9295d 100644 --- a/docs/zh-cn.md +++ b/docs/zh-cn.md @@ -14,7 +14,7 @@ mkdir docs && cd docs ``` ### 创建入口文件 -创建一个 `404.html` 文件,内容为 +创建一个 `index.html` 文件,内容为 ```html @@ -25,7 +25,7 @@ mkdir docs && cd docs
- + ``` @@ -66,7 +66,7 @@ docsify serve docs 更多选项参考 [docsify-cli](https://github.com/QingWei-Li/docsify-cli) ## 主题 -目前提供 vue.css 和 buble.css,直接修改 `404.html` 里的 cdn 地址即可 +目前提供 vue.css 和 buble.css,直接修改 `index.html` 里的 cdn 地址即可 ```html @@ -82,26 +82,18 @@ docsify serve docs ## 更多功能 ### 多页面 -`README.md` 作为主页面,如果需要其他页面,直接在文档目录下创建对应的 `*.md` 文件,例如创建一个 `guide.md` 那么对应的路由就是 `/guide`。 +`README.md` 作为主页面,如果需要其他页面,直接在文档目录下创建对应的 `*.md` 文件,例如创建一个 `guide.md` 那么对应的路由就是 `/#/guide`。 ### 导航 -导航需要自己写在 `404.html` 文件里,效果参考本文档 +导航需要自己写在 `index.html` 文件里,效果参考本文档 ```html ``` -### Hash router -`404.html` 对 SEO 不友好, 你可以用 `index.html` 代替并开启 `hash router` 功能。 [issue#7](https://github.com/QingWei-Li/docsify/issues/7) - -index.html - -```html - -``` ### CDN @@ -133,7 +125,7 @@ index.html ### 配置参数 #### repo -参考本文档的右上角的 GitHub 图标,如果要开启的话,将 `404.html` 里的 script 改成 +参考本文档的右上角的 GitHub 图标,如果要开启的话,将 `index.html` 里的 script 改成 ```html @@ -246,7 +238,7 @@ Sidebar 开关按钮 #### router -开启 hash router 功能,此时可以创建 `index.html` 作为入口文件,同时多页面切换不会重新加载资源。资源路径会被替换成 `/#/` 的形式。 +开启 hash router 功能,同时多页面切换不会重新加载资源。资源路径会被替换成 `/#/` 的形式。 ```html From 6e81e66441f989d8b86c5c1d43776ec498ad8811 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 24 Dec 2016 19:50:41 +0800 Subject: [PATCH 003/926] 404.dev => dev --- app.js | 4 ++-- 404.dev.html => dev.html | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename 404.dev.html => dev.html (100%) diff --git a/app.js b/app.js index e960cf4..ecce401 100644 --- a/app.js +++ b/app.js @@ -4,8 +4,8 @@ var fs = require('fs') http.createServer(function (req, res) { serveStatic('.')(req, res, function () { - res.writeHead(404, { 'Content-Type': 'text/html' }) - res.end(fs.readFileSync('404.dev.html')) + res.writeHead(200, { 'Content-Type': 'text/html' }) + res.end(fs.readFileSync('dev.html')) }) }).listen(3000, '0.0.0.0') diff --git a/404.dev.html b/dev.html similarity index 100% rename from 404.dev.html rename to dev.html From bd354094c09353ab0139800b2f7152ffe5e059d0 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 24 Dec 2016 20:32:04 +0800 Subject: [PATCH 004/926] =?UTF-8?q?=F0=9F=8E=84=20=20Merry=20Christmas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/_media/snow.js | 56 +++++++++++++++++++++++++++++++++++++++++++++ docs/index.html | 1 + 2 files changed, 57 insertions(+) create mode 100644 docs/_media/snow.js diff --git a/docs/_media/snow.js b/docs/_media/snow.js new file mode 100644 index 0000000..b0c20e5 --- /dev/null +++ b/docs/_media/snow.js @@ -0,0 +1,56 @@ +// Fork https://github.com/HermannBjorgvin/SnowJs/blob/master/snow.js +(function(){ + var canvas = document.createElement("canvas"); + var ctx = canvas.getContext("2d"); + var flakeArray = []; + + canvas.style.pointerEvents = "none"; + canvas.style.position = "absolute"; + canvas.style.top = 0; + canvas.style.left = 0; + canvas.style.width = "100vw"; + canvas.style.height = "100vh"; + document.body.appendChild(canvas); + + function canvasResize(){ + canvas.height = canvas.offsetHeight; + canvas.width = canvas.offsetWidth; + } + canvasResize(); + + window.onresize = function() { + canvasResize(); + }; + + var MyMath = Math; + + setInterval(function() { + ctx.clearRect(0, 0, canvas.width, canvas.height); + ctx.beginPath(); + + var random = MyMath.random(); + var distance = .05 + .95 * random; + + flake = {}; + flake.x = 1.5 * canvas.width * MyMath.random() - .5 * canvas.width; + flake.y = -9; + flake.velX = 2 * distance * (MyMath.random() / 2 + .5); + flake.velY = (4 + 2 * MyMath.random()) * distance; + flake.radius = MyMath.pow(5 * random, 2) / 5; + flake.update = function() { + var t = this; + t.x += t.velX; + t.y += t.velY; + ctx.beginPath(); + ctx.arc(t.x, t.y, t.radius, 0, 2 * MyMath.PI, !1); + ctx.fillStyle = "#FFF"; + ctx.fill() + }; + + flakeArray.push(flake); + + for (b = 0; b < flakeArray.length; b++) { + flakeArray[b].y > canvas.height ? flakeArray.splice(b, 1) : flakeArray[b].update() + } + }, 16); +})(); \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 615ba0c..1bb458e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -15,6 +15,7 @@
+ + diff --git a/src/render.js b/src/render.js index 5df8b20..23b2046 100644 --- a/src/render.js +++ b/src/render.js @@ -83,7 +83,10 @@ export function renderArticle (content) { renderSidebar.rendered = false renderNavbar.rendered = false - if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') new Vue({ el: 'main' }) // eslint-disable-line + if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') { + const vm = new Vue({ el: 'main' }) // eslint-disable-line + vm.$nextTick(_ => scrollActiveSidebar()) + } if (OPTIONS.auto2top) scroll2Top() } @@ -118,7 +121,9 @@ export function renderSidebar (content) { if (CACHE.sidebar && CACHE.sidebar === content) return CACHE.sidebar = content renderTo('aside.sidebar', content) - if (isToc) scrollActiveSidebar() + if (isToc) { + scrollActiveSidebar() + } toc = [] } From 7ce166501b7978cbcc3ba6ec669c82ec0c933e03 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Fri, 30 Dec 2016 17:58:39 +0800 Subject: [PATCH 014/926] Add render sub menu --- src/event.js | 11 +++++++++-- src/index.js | 25 ++++++++----------------- src/render.js | 32 +++++++++++++++----------------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/event.js b/src/event.js index 62133f3..8b4c7ae 100644 --- a/src/event.js +++ b/src/event.js @@ -16,7 +16,10 @@ export function scrollActiveSidebar () { const li = lis[i] let href = li.querySelector('a').getAttribute('href') - if (href !== '/') href = href.match(/#([^#]+)$/g)[0].slice(1) + if (href !== '/') { + const match = href.match('#([^#]+)$') + if (match && match.length) href = match[0].slice(1) + } nav[decodeURIComponent(href)] = li } @@ -61,18 +64,22 @@ export function activeLink (dom, activeParent) { dom = typeof dom === 'object' ? dom : document.querySelector(dom) if (!dom) return + let target ;[].slice.call(dom.querySelectorAll('a')).forEach(node => { - if (node.href === host) { + if (node.href === host && !target) { activeParent ? node.parentNode.setAttribute('class', 'active') : node.setAttribute('class', 'active') + target = node } else { activeParent ? node.parentNode.removeAttribute('class') : node.removeAttribute('class') } }) + + return target } /** diff --git a/src/index.js b/src/index.js index ba776a2..b81ca99 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,12 @@ import { load, camel2kebab, isNil, getRoute } from './util' -import { activeLink, scrollIntoView } from './event' +import { scrollIntoView } from './event' import * as render from './render' const OPTIONS = { el: '#app', repo: '', maxLevel: 6, + maxSubLevel: 0, sidebar: '', sidebarToggle: false, loadSidebar: null, @@ -40,7 +41,6 @@ const mainRender = function (cb) { const route = OPTIONS.basePath + getRoute() if (cacheRoute === route) return cb() - let wait let basePath = cacheRoute = route if (!/\//.test(basePath)) { @@ -72,22 +72,16 @@ const mainRender = function (cb) { if (OPTIONS.coverpage && page !== OPTIONS.homepage) render.renderCover() // render sidebar if (OPTIONS.loadSidebar) { - if (wait === false) cb() - wait = false + load(basePath + OPTIONS.loadSidebar) + .then(result => { + render.renderSidebar(result) + cb() + }) } else { cb() } }, _ => render.renderArticle(null)) - // Render sidebar - if (OPTIONS.loadSidebar) { - load(basePath + OPTIONS.loadSidebar).then(result => { - render.renderSidebar(result) - if (wait === false) cb() - wait = false - }) - } - // Render navbar if (OPTIONS.loadNavbar) { load(basePath + OPTIONS.loadNavbar).then(render.renderNavbar) @@ -98,10 +92,7 @@ const Docsify = function () { const dom = document.querySelector(OPTIONS.el) || document.body const replace = dom !== document.body const main = function () { - mainRender(_ => { - activeLink('aside.sidebar', true) - scrollIntoView() - }) + mainRender(_ => scrollIntoView()) } // Render app diff --git a/src/render.js b/src/render.js index 23b2046..3e3ea7b 100644 --- a/src/render.js +++ b/src/render.js @@ -78,10 +78,7 @@ export function renderApp (dom, replace) { */ export function renderArticle (content) { renderTo('article', content ? marked(content) : 'not found') - if (!renderSidebar.rendered) renderSidebar(null, OPTIONS) - if (!renderNavbar.rendered) renderNavbar(null, OPTIONS) - renderSidebar.rendered = false - renderNavbar.rendered = false + if (!OPTIONS.sidebar && !OPTIONS.loadSidebar) renderSidebar() if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') { const vm = new Vue({ el: 'main' }) // eslint-disable-line @@ -96,7 +93,6 @@ export function renderArticle (content) { export function renderNavbar (content) { if (CACHE.navbar && CACHE.navbar === content) return CACHE.navbar = content - renderNavbar.rendered = true if (content) renderTo('nav', marked(content)) activeLink('nav') @@ -106,25 +102,27 @@ export function renderNavbar (content) { * sidebar */ export function renderSidebar (content) { - let isToc = false + let html if (content) { - content = marked(content) + html = marked(content) } else if (OPTIONS.sidebar) { - content = tpl.tree(OPTIONS.sidebar, '