Compare commits

...
23 Commits
Author SHA1 Message Date
qingwei.li 543cbbce81 -> v2.0.2 2017-02-05 14:50:09 +08:00
qingwei.li 72c34152d4 bump: 2.0.2 2017-02-05 14:50:04 +08:00
qingwei.li 44708554f7 fix: button style in cover page 2017-02-05 14:48:57 +08:00
qingwei.li 6e35f6481a docs: update api 2017-02-05 13:53:36 +08:00
qingwei.li 115c80b2f2 -> v2.0.1 2017-02-05 13:50:36 +08:00
qingwei.li addb34d38a bump: 2.0.1 2017-02-05 13:47:32 +08:00
qingwei.li 1f12009a98 fix border style. 2017-02-05 13:47:03 +08:00
qingwei.li 4abcb02824 -> v2.0.0 2017-02-05 10:27:48 +08:00
qingwei.li d45e325d54 bump 2.0 2017-02-05 10:27:42 +08:00
qingwei.li f2f37eec46 Update version number 2017-02-05 10:26:25 +08:00
qingwei.li fef969f55d clean api 2017-02-05 10:26:25 +08:00
qingwei.li 5cc9f0514c feat: customize the theme color 2017-02-05 10:26:25 +08:00
qingwei.li ae1ad735d5 -> v1.10.5 2017-01-28 11:12:26 +08:00
qingwei.li a35a336d00 bump 1.10.5 2017-01-28 11:12:22 +08:00
qingwei.li 3ec7c89bbb fix initialize the Vue instance 2017-01-28 11:11:58 +08:00
qingwei.li 89f0b1fcbd -> v1.10.4 2017-01-27 15:14:23 +08:00
qingwei.li 6f5bb1a527 bump 1.10.4 2017-01-27 15:14:15 +08:00
qingwei.li 98ec020c7a fix execute script 2017-01-27 15:13:51 +08:00
qingwei.li bb13ddd5df -> v1.10.3 2017-01-27 12:45:42 +08:00
qingwei.li e69efb8954 bump 1.10.3 2017-01-27 12:45:16 +08:00
qingwei.li 0e5f28cf60 Add change log 2017-01-27 12:44:54 +08:00
qingwei.li 7db1f1034a Fix sidebar scroll, fixed #63 2017-01-27 12:44:05 +08:00
qingwei.li b0320416a5 compatible vuep, fixed QingWei-Li/vuep/issues/2 2017-01-27 12:01:36 +08:00
24 changed files with 299 additions and 263 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
{
"extends": ["vue"],
"globals": {
"XMLHttpRequest": true
"XMLHttpRequest": true,
"__docsify__": true
}
}
+29
View File
@@ -1,3 +1,32 @@
## 2.0.2
### Bug fixes
- fix button style in cover page.
## 2.0.1
### Bug fixes
- border style.
## 2.0.0
### Features
- Customize the theme color
### Break change
- Remove `data-router`, `data-sidebar`, `data-sidebar-toggle` APIs
## 1.10.5
### Bug fixes
- fix initialize the Vue instance
## 1.10.4
### Bug fixes
- fix execute script
## 1.10.3
### Bug fixes
- compatible vuep QingWei-Li/vuep/issues/2
- fix sidebar scroll, fixed #63
## 1.10.2
### Bug fixes
- Fix render emojis again
+6 -2
View File
@@ -25,7 +25,7 @@
- Support emoji :laughing:
## Quick start
Create a `index.html` and using `hash router`.
Create a `index.html`.
index.html
@@ -39,7 +39,7 @@ index.html
<body>
<div id="app"></div>
</body>
<script src="//unpkg.com/docsify" data-router></script>
<script src="//unpkg.com/docsify"></script>
</html>
```
@@ -47,6 +47,10 @@ index.html
- UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/)
- jsDelivr [http://www.jsdelivr.com/projects/docsify](http://www.jsdelivr.com/projects/docsify)
## Browser Support
Modern browsers and Internet Explorer 9+.
## Showcase
These open-source projects are using docsify to generate their sites. Pull requests welcome : )
+9 -1
View File
@@ -3,7 +3,15 @@ var cssnano = require('cssnano').process
var resolve = require('path').resolve
var postcss = require('postcss')
var processor = postcss([require('postcss-salad')])
var processor = postcss([require('postcss-salad')({
features: {
precss: {
properties: {
preserve: true
}
}
}
})])
var saveMin = function (file, content) {
fs.writeFileSync(resolve(__dirname, '../lib/themes/', file), content)
+2 -2
View File
@@ -5,8 +5,8 @@
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="/themes/vue.css">
</head>
<body class="">
<body>
<div id="app"></div>
</body>
<script src="/lib/docsify.js" data-repo="qingwei-li/docsify" data-name="docsify" data-auto2top data-sidebar-toggle data-router></script>
<script src="/lib/docsify.js" data-repo="qingwei-li/docsify" data-name="docsify" data-auto2top></script>
</html>
+18 -63
View File
@@ -20,7 +20,7 @@ Create a `index.html` file
<body>
<div id="app"></div>
</body>
<script src="//unpkg.com/docsify" data-router></script>
<script src="//unpkg.com/docsify"></script>
</html>
```
@@ -191,7 +191,7 @@ We can write the Vue syntax directly in the markdown file, when the Vue library
index.html
```html
<script src="//unpkg.com/vue"></script>
<script src="//unpkg.com/docsify" data-router></script>
<script src="//unpkg.com/docsify"></script>
```
```markdown
@@ -260,50 +260,6 @@ window.$docsify = {
}
```
### sidebar-toggle
Sidebar with toggle
```html
<script src="//unpkg.com/docsify" data-sidebar-toggle></script>
```
```js
window.$docsify = {
sidebarToggle: true
}
```
### sidebar
Custom sidebar. If it's set, the TOC will be disabled. Bind global variables on the `data-sidebar`.
![image](https://cloud.githubusercontent.com/assets/7565692/20647425/de5ab1c2-b4ce-11e6-863a-135868f2f9b4.png)
```html
<script>
window.sidebar = [
{ slug: '/', title: 'Home' },
{
slug: '/pageA',
title: 'page A',
children: [
{ slug: '/pageA/childrenB', title: 'children B' }
]
},
{ slug: '/PageC', title: 'Page C' }
]
</script>
<script src="/lib/docsify.js" data-sidebar="sidebar"></script>
```
```js
window.$docsify = {
sidebar: 'sidebar'
}
```
### load-sidebar
Load sidebar markdown file. If it is configured, load the current directory `_sidebar.md` by default. If the file doesn't exist, the sidebar will appear as a TOC.
@@ -388,20 +344,6 @@ If you write a sub level list, it will generate a dropdown list.
- [chinese](/zh-cn)
```
### router
Hash router.
```html
<script src="/lib/docsify.js" data-router></script>
```
```js
window.$docsify = {
router: true
}
```
### auto2top
@@ -423,7 +365,7 @@ window.$docsify = {
### homepage
`README.md` will be rendered as a homepage for your website in the docs folder, but sometimes we want to specify another file as a homepage, or even use the `README.md` in your repo. We can use (need `data-router`):
`README.md` will be rendered as a homepage for your website in the docs folder, but sometimes we want to specify another file as a homepage, or even use the `README.md` in your repo.
```html
<script src="/lib/docsify.js" data-homepage="https://raw.githubusercontent.com/QingWei-Li/docsify/master/README.md"></script>
@@ -439,7 +381,7 @@ window.$docsify = {
```
### basePath
### base-path
If your HTML entry file and the markdown files are in different directories, we can use:
@@ -488,7 +430,7 @@ window.$docsify = {
}
```
### nameLink
### name-link
Name link. The default value is `window.location.pathname`.
@@ -503,4 +445,17 @@ window.$docsify = {
}
```
### theme-color
Customize the theme color.
```html
<script src="/lib/docsify.js" data-theme-color="#3F51B5"></script>
```
```js
window.$docsify = {
themeColor: '#3F51B5'
}
```
+1 -1
View File
@@ -1,6 +1,6 @@
![logo](_media/icon.svg)
# docsify <small>1.10.2</small>
# docsify <small>2.0.2</small>
> A magical documentation site generator.
+1 -3
View File
@@ -18,10 +18,8 @@
<script
src="//unpkg.com/docsify/lib/docsify.min.js"
data-max-level="4"
data-sidebar-toggle
data-coverpage
data-name="docsify"
data-router></script>
data-name="docsify"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
</html>
+19 -64
View File
@@ -25,7 +25,7 @@ mkdir docs && cd docs
<body>
<div id="app"></div>
</body>
<script src="//unpkg.com/docsify" data-router></script>
<script src="//unpkg.com/docsify"></script>
</html>
```
@@ -201,7 +201,7 @@ window.$docsify = {
index.html
```html
<script src="//unpkg.com/vue"></script>
<script src="//unpkg.com/docsify" data-router></script>
<script src="//unpkg.com/docsify"></script>
```
```markdown
@@ -271,51 +271,6 @@ window.$docsify = {
}
```
### sidebar-toggle
Sidebar 开关按钮
```html
<script src="//unpkg.com/docsify" data-sidebar-toggle></script>
```
```js
window.$docsify = {
sidebarToggle: true
}
```
### sidebar
设置后 TOC 功能将不可用,适合导航较多的文档,`data-sidebar` 传入全局变量名。
![image](https://cloud.githubusercontent.com/assets/7565692/20647425/de5ab1c2-b4ce-11e6-863a-135868f2f9b4.png)
```html
<script>
window.sidebar = [
{ slug: '/', title: 'Home' },
{
slug: '/pageA',
title: 'page A',
children: [
{ slug: '/pageA/childrenB', title: 'children B' }
]
},
{ slug: '/PageC', title: 'Page C' }
]
</script>
<script src="/lib/docsify.js" data-sidebar="sidebar"></script>
```
```js
window.$docsify = {
sidebar: 'sidebar'
}
```
### load-sidebar
读取侧边栏配置文件,如果配置,默认加载当前目录下的 `_sidebar.md`。如果文件不存在,会显示 TOC 作为侧边栏内容。如果你有二级目录,也应该放置一份配置文件。
@@ -400,20 +355,6 @@ window.$docsify = {
```
### router
开启 hash router 功能,同时多页面切换不会重新加载资源。资源路径会被替换成 `/#/` 的形式。
```html
<script src="/lib/docsify.js" data-router></script>
```
```js
window.$docsify = {
router: true
}
```
### auto2top
切换路由时自动跳转到页面顶部
@@ -431,7 +372,7 @@ window.$docsify = {
### homepage
默认情况下网站会将根目录下 `README.md` 作为首页渲染,但是有些时候我们想指定其他文件,甚至想直接将 repo 下的 README 作为首页。你可以这样做(需要设置 `data-router`):
默认情况下网站会将根目录下 `README.md` 作为首页渲染,但是有些时候我们想指定其他文件,甚至想直接将 repo 下的 README 作为首页。
```html
@@ -446,7 +387,7 @@ window.$docsify = {
}
```
### basePath
### base-path
指定加载文档的路径,如果你的 HTML 入口文件和文档是放在不同地方,你可以设置:
@@ -497,7 +438,7 @@ window.$docsify = {
}
```
### nameLink
### name-link
项目名链接,默认为 `window.location.pathname`
@@ -511,3 +452,17 @@ window.$docsify = {
}
```
### theme-color
自定义主题色。
```html
<script src="/lib/docsify.js" data-theme-color="#3F51B5"></script>
```
```js
window.$docsify = {
themeColor: '#3F51B5'
}
```
+90 -42
View File
@@ -184,6 +184,8 @@ function scrollActiveSidebar () {
var hoveredOverSidebar = false;
var anchors = document.querySelectorAll('.anchor');
var sidebar = document.querySelector('aside.sidebar');
var sidebarHeight = sidebar.clientHeight;
var nav = {};
var lis = sidebar.querySelectorAll('li');
var active = sidebar.querySelector('li.active');
@@ -222,7 +224,25 @@ function scrollActiveSidebar () {
li.classList.add('active');
active = li;
!hoveredOverSidebar && !sticky.noSticky && active.scrollIntoView(false);
// scroll into view
// https://github.com/vuejs/vuejs.org/blob/master/themes/vue/source/js/common.js#L282-L297
if (!hoveredOverSidebar && !sticky.noSticky) {
var currentPageOffset = 0;
var currentActiveOffset = active.offsetTop + active.clientHeight + 40;
var currentActiveIsInView = (
active.offsetTop >= sidebar.scrollTop &&
currentActiveOffset <= sidebar.scrollTop + sidebarHeight
);
var linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight;
var newScrollTop = currentActiveIsInView
? sidebar.scrollTop
: linkNotFurtherThanSidebarHeight
? currentPageOffset
: currentActiveOffset - sidebarHeight;
sidebar.scrollTop = newScrollTop;
}
}
window.removeEventListener('scroll', highlight);
@@ -2427,8 +2447,8 @@ function corner (data) {
/**
* Render main content
*/
function main (tpl) {
var aside = tpl + "<aside class=\"sidebar\"></aside>";
function main () {
var aside = (toggle()) + "<aside class=\"sidebar\"></aside>";
return (isMobile() ? (aside + "<main>") : ("<main>" + aside)) +
"<section class=\"content\">\n <article class=\"markdown-section\"></article>\n </section>\n </main>"
@@ -2473,7 +2493,34 @@ function helper (className, content) {
return ("<p class=\"" + className + "\">" + (content.slice(5).trim()) + "</p>")
}
var OPTIONS$1 = {};
function theme (color) {
return ("<style>:root{--theme-color: " + color + ";}</style>")
}
function replaceVar (block) {
block.innerHTML = block.innerHTML.replace(/var\(\s*--theme-color.*?\)/g, __docsify__.themeColor);
}
function cssVars () {
// variable support
if (window.CSS && window.CSS.supports && window.CSS.supports('(--foo: red)')) { return }
var styleBlocks = document.querySelectorAll('style:not(.inserted),link');[].forEach.call(styleBlocks, function (block) {
if (block.nodeName === 'STYLE') {
replaceVar(block);
} else if (block.nodeName === 'LINK') {
load(block.getAttribute('href'))
.then(function (res) {
var style = document.createElement('style');
style.innerHTML = res;
document.head.appendChild(style);
replaceVar(style);
});
}
});
}
var markdown = marked;
var toc = [];
var CACHE = {};
@@ -2488,11 +2535,8 @@ var renderTo = function (dom, content) {
/**
* init render
* @param {Object} options
*/
function init (options) {
OPTIONS$1 = options;
function init () {
var renderer = new marked.Renderer();
/**
* render anchor tag
@@ -2502,10 +2546,7 @@ function init (options) {
var slug = slugify(text);
var route = '';
if (OPTIONS$1.router) {
route = "#/" + (getRoute());
}
route = "#/" + (getRoute());
toc.push({ level: level, slug: (route + "#" + (encodeURIComponent(slug))), title: text });
return ("<h" + level + " id=\"" + slug + "\"><a href=\"" + route + "#" + slug + "\" data-id=\"" + slug + "\" class=\"anchor\"><span>" + text + "</span></a></h" + level + ">")
@@ -2519,7 +2560,7 @@ function init (options) {
return ("<pre v-pre data-lang=\"" + lang + "\"><code class=\"lang-" + lang + "\">" + (hl.replace(/:/g, '__colon__')) + "</code></pre>")
};
renderer.link = function (href, title, text) {
if (OPTIONS$1.router && !/:/.test(href)) {
if (!/:/.test(href)) {
href = ("#/" + href).replace(/\/\//g, '/');
}
@@ -2534,11 +2575,11 @@ function init (options) {
return ("<p>" + text + "</p>")
};
if (typeof OPTIONS$1.markdown === 'function') {
if (typeof __docsify__.markdown === 'function') {
markdown.setOptions({ renderer: renderer });
markdown = OPTIONS$1.markdown.call(this, markdown);
markdown = __docsify__.markdown.call(this, markdown);
} else {
markdown.setOptions(merge({ renderer: renderer }, OPTIONS$1.markdown));
markdown.setOptions(merge({ renderer: renderer }, __docsify__.markdown));
}
var md = markdown;
@@ -2552,17 +2593,23 @@ function init (options) {
function renderApp (dom, replace) {
var nav = document.querySelector('nav') || document.createElement('nav');
if (!OPTIONS$1.repo) { nav.classList.add('no-badge'); }
if (!__docsify__.repo) { nav.classList.add('no-badge'); }
dom[replace ? 'outerHTML' : 'innerHTML'] = corner(OPTIONS$1.repo) +
(OPTIONS$1.coverpage ? cover() : '') +
main(OPTIONS$1.sidebarToggle ? toggle() : '');
dom[replace ? 'outerHTML' : 'innerHTML'] = corner(__docsify__.repo) +
(__docsify__.coverpage ? cover() : '') +
main();
document.body.insertBefore(nav, document.body.children[0]);
// theme color
if (__docsify__.themeColor) {
document.head.innerHTML += theme(__docsify__.themeColor);
cssVars();
}
// bind toggle
bindToggle('button.sidebar-toggle');
// bind sticky effect
if (OPTIONS$1.coverpage) {
if (__docsify__.coverpage) {
!isMobile() && window.addEventListener('scroll', sticky);
} else {
document.body.classList.add('sticky');
@@ -2574,19 +2621,24 @@ function renderApp (dom, replace) {
*/
function renderArticle (content) {
renderTo('article', content ? markdown(content) : 'not found');
if (!OPTIONS$1.sidebar && !OPTIONS$1.loadSidebar) { renderSidebar(); }
if (!__docsify__.loadSidebar) { renderSidebar(); }
if (content && typeof Vue !== 'undefined') {
var script = content.match('<script[^>]*?>([^<]+)</script>');
script && document.body.querySelector('article script').remove();
CACHE.vm && CACHE.vm.$destroy();
CACHE.vm = script
? new Function(("return " + (script[1].trim())))()
var script = [].slice.call(
document.body.querySelectorAll('article>script'))
.filter(function (script) { return !/template/.test(script.type); }
)[0];
var code = script ? script.innerText.trim() : null;
script && script.remove();
CACHE.vm = code
? new Function(("return " + code))()
: new Vue({ el: 'main' }); // eslint-disable-line
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); });
}
if (OPTIONS$1.auto2top) { setTimeout(function () { return scroll2Top(OPTIONS$1.auto2top); }, 0); }
if (__docsify__.auto2top) { setTimeout(function () { return scroll2Top(__docsify__.auto2top); }, 0); }
}
/**
@@ -2610,13 +2662,11 @@ function renderSidebar (content) {
html = markdown(content);
// find url tag
html = html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0];
} else if (OPTIONS$1.sidebar) {
html = tree(OPTIONS$1.sidebar, '<ul>');
} else {
html = tree(genTree(toc, OPTIONS$1.maxLevel), '<ul>');
html = tree(genTree(toc, __docsify__.maxLevel), '<ul>');
}
html = (OPTIONS$1.name ? ("<h1><a href=\"" + (OPTIONS$1.nameLink) + "\">" + (OPTIONS$1.name) + "</a></h1>") : '') + html;
html = (__docsify__.name ? ("<h1><a href=\"" + (__docsify__.nameLink) + "\">" + (__docsify__.name) + "</a></h1>") : '') + html;
renderTo('aside.sidebar', html);
var target = activeLink('aside.sidebar', true);
if (target) { renderSubSidebar(target); }
@@ -2626,8 +2676,8 @@ function renderSidebar (content) {
}
function renderSubSidebar (target) {
if (!OPTIONS$1.subMaxLevel) { return }
target.parentNode.innerHTML += tree(genTree(toc, OPTIONS$1.subMaxLevel), '<ul>');
if (!__docsify__.subMaxLevel) { return }
target.parentNode.innerHTML += tree(genTree(toc, __docsify__.subMaxLevel), '<ul>');
}
/**
@@ -2710,16 +2760,14 @@ var OPTIONS = merge({
repo: '',
maxLevel: 6,
subMaxLevel: 0,
sidebar: '',
sidebarToggle: false,
loadSidebar: null,
loadNavbar: null,
router: false,
homepage: 'README.md',
coverpage: '',
basePath: '',
auto2top: false,
name: '',
themeColor: '',
nameLink: window.location.pathname
}, window.$docsify);
var script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop();
@@ -2735,9 +2783,11 @@ if (script) {
if (OPTIONS.coverpage === true) { OPTIONS.coverpage = '_coverpage.md'; }
if (OPTIONS.repo === true) { OPTIONS.repo = ''; }
if (OPTIONS.name === true) { OPTIONS.name = ''; }
if (OPTIONS.sidebar) { OPTIONS.sidebar = window[OPTIONS.sidebar]; }
}
// utils
window.__docsify__ = OPTIONS;
// load options
init(OPTIONS);
@@ -2808,10 +2858,8 @@ var Docsify = function () {
// Render app
renderApp(dom, replace);
main();
if (OPTIONS.router) {
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
window.addEventListener('hashchange', main);
}
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
window.addEventListener('hashchange', main);
};
var index = Docsify();
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docsify",
"version": "1.10.2",
"version": "2.0.2",
"description": "A magical documentation generator.",
"main": "lib/docsify.js",
"files": [
+21 -1
View File
@@ -10,6 +10,8 @@ export function scrollActiveSidebar () {
let hoveredOverSidebar = false
const anchors = document.querySelectorAll('.anchor')
const sidebar = document.querySelector('aside.sidebar')
const sidebarHeight = sidebar.clientHeight
const nav = {}
const lis = sidebar.querySelectorAll('li')
let active = sidebar.querySelector('li.active')
@@ -48,7 +50,25 @@ export function scrollActiveSidebar () {
li.classList.add('active')
active = li
!hoveredOverSidebar && !sticky.noSticky && active.scrollIntoView(false)
// scroll into view
// https://github.com/vuejs/vuejs.org/blob/master/themes/vue/source/js/common.js#L282-L297
if (!hoveredOverSidebar && !sticky.noSticky) {
const currentPageOffset = 0
const currentActiveOffset = active.offsetTop + active.clientHeight + 40
const currentActiveIsInView = (
active.offsetTop >= sidebar.scrollTop &&
currentActiveOffset <= sidebar.scrollTop + sidebarHeight
)
const linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight
const newScrollTop = currentActiveIsInView
? sidebar.scrollTop
: linkNotFurtherThanSidebarHeight
? currentPageOffset
: currentActiveOffset - sidebarHeight
sidebar.scrollTop = newScrollTop
}
}
window.removeEventListener('scroll', highlight)
+6 -8
View File
@@ -7,16 +7,14 @@ const OPTIONS = merge({
repo: '',
maxLevel: 6,
subMaxLevel: 0,
sidebar: '',
sidebarToggle: false,
loadSidebar: null,
loadNavbar: null,
router: false,
homepage: 'README.md',
coverpage: '',
basePath: '',
auto2top: false,
name: '',
themeColor: '',
nameLink: window.location.pathname
}, window.$docsify)
const script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop()
@@ -32,9 +30,11 @@ if (script) {
if (OPTIONS.coverpage === true) OPTIONS.coverpage = '_coverpage.md'
if (OPTIONS.repo === true) OPTIONS.repo = ''
if (OPTIONS.name === true) OPTIONS.name = ''
if (OPTIONS.sidebar) OPTIONS.sidebar = window[OPTIONS.sidebar]
}
// utils
window.__docsify__ = OPTIONS
// load options
render.init(OPTIONS)
@@ -105,10 +105,8 @@ const Docsify = function () {
// Render app
render.renderApp(dom, replace)
main()
if (OPTIONS.router) {
if (!/^#\//.test(window.location.hash)) window.location.hash = '#/'
window.addEventListener('hashchange', main)
}
if (!/^#\//.test(window.location.hash)) window.location.hash = '#/'
window.addEventListener('hashchange', main)
}
export default Docsify()
+27
View File
@@ -0,0 +1,27 @@
import { load } from './util'
function replaceVar (block) {
block.innerHTML = block.innerHTML.replace(/var\(\s*--theme-color.*?\)/g, __docsify__.themeColor)
}
export function cssVars () {
// variable support
if (window.CSS && window.CSS.supports && window.CSS.supports('(--foo: red)')) return
const styleBlocks = document.querySelectorAll('style:not(.inserted),link')
;[].forEach.call(styleBlocks, block => {
if (block.nodeName === 'STYLE') {
replaceVar(block)
} else if (block.nodeName === 'LINK') {
load(block.getAttribute('href'))
.then(res => {
const style = document.createElement('style')
style.innerHTML = res
document.head.appendChild(style)
replaceVar(style)
})
}
})
}
+34 -31
View File
@@ -2,9 +2,9 @@ import marked from 'marked'
import Prism from 'prismjs'
import * as tpl from './tpl'
import * as event from './event'
import * as polyfill from './polyfill'
import { genTree, getRoute, isMobile, slugify, merge, emojify } from './util'
let OPTIONS = {}
let markdown = marked
let toc = []
const CACHE = {}
@@ -19,11 +19,8 @@ const renderTo = function (dom, content) {
/**
* init render
* @param {Object} options
*/
export function init (options) {
OPTIONS = options
export function init () {
const renderer = new marked.Renderer()
/**
* render anchor tag
@@ -33,10 +30,7 @@ export function init (options) {
const slug = slugify(text)
let route = ''
if (OPTIONS.router) {
route = `#/${getRoute()}`
}
route = `#/${getRoute()}`
toc.push({ level, slug: `${route}#${encodeURIComponent(slug)}`, title: text })
return `<h${level} id="${slug}"><a href="${route}#${slug}" data-id="${slug}" class="anchor"><span>${text}</span></a></h${level}>`
@@ -48,7 +42,7 @@ export function init (options) {
return `<pre v-pre data-lang="${lang}"><code class="lang-${lang}">${hl.replace(/:/g, '__colon__')}</code></pre>`
}
renderer.link = function (href, title, text) {
if (OPTIONS.router && !/:/.test(href)) {
if (!/:/.test(href)) {
href = `#/${href}`.replace(/\/\//g, '/')
}
@@ -63,11 +57,11 @@ export function init (options) {
return `<p>${text}</p>`
}
if (typeof OPTIONS.markdown === 'function') {
if (typeof __docsify__.markdown === 'function') {
markdown.setOptions({ renderer })
markdown = OPTIONS.markdown.call(this, markdown)
markdown = __docsify__.markdown.call(this, markdown)
} else {
markdown.setOptions(merge({ renderer }, OPTIONS.markdown))
markdown.setOptions(merge({ renderer }, __docsify__.markdown))
}
const md = markdown
@@ -81,17 +75,23 @@ export function init (options) {
export function renderApp (dom, replace) {
const nav = document.querySelector('nav') || document.createElement('nav')
if (!OPTIONS.repo) nav.classList.add('no-badge')
if (!__docsify__.repo) nav.classList.add('no-badge')
dom[replace ? 'outerHTML' : 'innerHTML'] = tpl.corner(OPTIONS.repo) +
(OPTIONS.coverpage ? tpl.cover() : '') +
tpl.main(OPTIONS.sidebarToggle ? tpl.toggle() : '')
dom[replace ? 'outerHTML' : 'innerHTML'] = tpl.corner(__docsify__.repo) +
(__docsify__.coverpage ? tpl.cover() : '') +
tpl.main()
document.body.insertBefore(nav, document.body.children[0])
// theme color
if (__docsify__.themeColor) {
document.head.innerHTML += tpl.theme(__docsify__.themeColor)
polyfill.cssVars()
}
// bind toggle
event.bindToggle('button.sidebar-toggle')
// bind sticky effect
if (OPTIONS.coverpage) {
if (__docsify__.coverpage) {
!isMobile() && window.addEventListener('scroll', event.sticky)
} else {
document.body.classList.add('sticky')
@@ -103,19 +103,24 @@ export function renderApp (dom, replace) {
*/
export function renderArticle (content) {
renderTo('article', content ? markdown(content) : 'not found')
if (!OPTIONS.sidebar && !OPTIONS.loadSidebar) renderSidebar()
if (!__docsify__.loadSidebar) renderSidebar()
if (content && typeof Vue !== 'undefined') {
const script = content.match('<script[^>]*?>([^<]+)</script>')
script && document.body.querySelector('article script').remove()
CACHE.vm && CACHE.vm.$destroy()
CACHE.vm = script
? new Function(`return ${script[1].trim()}`)()
const script = [].slice.call(
document.body.querySelectorAll('article>script'))
.filter(script => !/template/.test(script.type)
)[0]
const code = script ? script.innerText.trim() : null
script && script.remove()
CACHE.vm = code
? new Function(`return ${code}`)()
: new Vue({ el: 'main' }) // eslint-disable-line
CACHE.vm && CACHE.vm.$nextTick(_ => event.scrollActiveSidebar())
}
if (OPTIONS.auto2top) setTimeout(() => event.scroll2Top(OPTIONS.auto2top), 0)
if (__docsify__.auto2top) setTimeout(() => event.scroll2Top(__docsify__.auto2top), 0)
}
/**
@@ -139,13 +144,11 @@ export function renderSidebar (content) {
html = markdown(content)
// find url tag
html = html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0]
} else if (OPTIONS.sidebar) {
html = tpl.tree(OPTIONS.sidebar, '<ul>')
} else {
html = tpl.tree(genTree(toc, OPTIONS.maxLevel), '<ul>')
html = tpl.tree(genTree(toc, __docsify__.maxLevel), '<ul>')
}
html = (OPTIONS.name ? `<h1><a href="${OPTIONS.nameLink}">${OPTIONS.name}</a></h1>` : '') + html
html = (__docsify__.name ? `<h1><a href="${__docsify__.nameLink}">${__docsify__.name}</a></h1>` : '') + html
renderTo('aside.sidebar', html)
const target = event.activeLink('aside.sidebar', true)
if (target) renderSubSidebar(target)
@@ -155,8 +158,8 @@ export function renderSidebar (content) {
}
export function renderSubSidebar (target) {
if (!OPTIONS.subMaxLevel) return
target.parentNode.innerHTML += tpl.tree(genTree(toc, OPTIONS.subMaxLevel), '<ul>')
if (!__docsify__.subMaxLevel) return
target.parentNode.innerHTML += tpl.tree(genTree(toc, __docsify__.subMaxLevel), '<ul>')
}
/**
+5 -3
View File
@@ -72,9 +72,11 @@ section.cover {
.cover-main p:last-child a {
border-radius: 2em;
border: 1px solid $color-primary;
border-width: 1px;
border-style: solid;
border-color: var(--theme-color, $color-primary);
box-sizing: border-box;
color: $color-primary;
color: var(--theme-color, $color-primary);
font-size: 1.05em;
letter-spacing: 0.1em;
padding: 0.75em 2em;
@@ -85,7 +87,7 @@ section.cover {
&:last-child {
margin-right: 0;
background-color: $color-primary;
background-color: var(--theme-color, $color-primary);
color: #fff;
&:hover {
+10 -26
View File
@@ -13,7 +13,7 @@
}
.progress {
background-color: $color-primary;
background-color: var(--theme-color, $color-primary);
height: 2px;
left: 0px;
position: fixed;
@@ -86,12 +86,12 @@ nav {
transition: color .3s;
&:hover {
color: $color-primary;
color: var(--theme-color, $color-primary);
}
&.active {
color: $color-primary;
border-bottom: 2px solid $color-primary;
color: var(--theme-color, $color-primary);
border-bottom: 2px solid var(--theme-color, $color-primary);
}
}
@@ -103,7 +103,9 @@ nav {
ul {
border-radius: 2px;
background-color: rgba($color-bg, .6);
border: 1px solid $color-primary;
border-width: 1px;
border-style: solid;
border-color: var(--theme-color, $color-primary);
opacity: 0;
overflow: hidden;
padding: 0;
@@ -160,7 +162,7 @@ nav {
color: $color-bg;
height: 80px;
width: 80px;
fill: $color-primary;
fill: var(--theme-color, $color-primary);
}
}
@@ -193,16 +195,7 @@ main {
transition: transform 250ms ease-out;
width: $sidebar-width;
z-index: 20;
margin-bottom: 40px;
&::after {
content: '';
position: inherit;
left: calc($sidebar-width - 1px);
top: 0;
height: 100vh;
border-right: 1px solid rgba(0, 0, 0, .07);
}
border-right: 1px solid rgba(0, 0, 0, .07);
> h1 {
text-align: center;
@@ -255,7 +248,7 @@ main {
}
span {
background-color: $color-primary;
background-color: var(--theme-color, $color-primary);
display: block;
size: 16px 2px;
margin-bottom: 4px;
@@ -384,15 +377,6 @@ body.close {
position: fixed;
}
.sidebar {
margin-bottom: 0;
border-right: 1px solid rgba(0, 0, 0, .07);
&::after {
content: none;
}
}
nav {
margin-top: 16px;
}
+2 -2
View File
@@ -47,7 +47,7 @@ $sidebar-width: 16em;
}
.markdown-section a {
color: $color-primary;
color: var(--theme-color, $color-primary);
font-weight: 400;
}
@@ -110,7 +110,7 @@ $sidebar-width: 16em;
.markdown-section blockquote {
color: #858585;
border-left: 4px solid $color-primary;
border-left: 4px solid var(--theme-color, $color-primary);
margin: 2em 0;
padding-left: 20px;
}
+5 -5
View File
@@ -38,7 +38,7 @@ body {
}
ul li.active>a {
color: $color-primary;
color: var(--theme-color, $color-primary);
font-weight: 600;
}
}
@@ -54,7 +54,7 @@ body {
}
.markdown-section a {
color: $color-primary;
color: var(--theme-color, $color-primary);
font-weight: 600;
}
@@ -107,7 +107,7 @@ body {
.markdown-section blockquote {
color: #858585;
border-left: 4px solid $color-primary;
border-left: 4px solid var(--theme-color, $color-primary);
margin: 2em 0;
padding-left: 20px;
}
@@ -179,7 +179,7 @@ body {
}
.token.string {
color: $color-primary;
color: var(--theme-color, $color-primary);
}
.token.selector {
@@ -201,7 +201,7 @@ body {
.token.control,
.token.directive,
.token.unit {
color: $color-primary;
color: var(--theme-color, $color-primary);
}
.token.keyword {
+6 -2
View File
@@ -22,8 +22,8 @@ export function corner (data) {
/**
* Render main content
*/
export function main (tpl) {
const aside = `${tpl}<aside class="sidebar"></aside>`
export function main () {
const aside = `${toggle()}<aside class="sidebar"></aside>`
return (isMobile() ? `${aside}<main>` : `<main>${aside}`) +
`<section class="content">
@@ -75,3 +75,7 @@ export function tree (toc, tpl = '') {
export function helper (className, content) {
return `<p class="${className}">${content.slice(5).trim()}</p>`
}
export function theme (color) {
return `<style>:root{--theme-color: ${color};}</style>`
}