* Add cover page

* Update doc

* Add kbd style, resolve #37

* headling can cliked, resolve #36

* Update change log, close #35

* Update docs
This commit is contained in:
cinwell.li 2016-12-22 00:24:54 +08:00 committed by GitHub
parent b14fcf7d1c
commit 50addfdac6
14 changed files with 312 additions and 48 deletions

View File

@ -1,3 +1,13 @@
## 1.3.0
### Features
- Add cover page
### Bug fixes
- sidebar highlight
- headling can be cliked
- add `<kbd>` style
## 1.2.0 ## 1.2.0
### Features ### Features
- custom basePath - custom basePath

View File

@ -1,16 +1,3 @@
<p align="center">
<img alt="docsify" src="https://cloud.githubusercontent.com/assets/7565692/21292094/5c206de4-c533-11e6-9493-29ea67b01dde.png">
</p>
<p align="center">
A magical documentation site generator.
</p>
## Features
- Simple and lightweight (~12kb gzipped)
- Multiple themes
- Not build static html files
## Quick Start ## Quick Start
### Create a project ### Create a project
@ -107,6 +94,28 @@ Code in `404.html`
- UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/) - UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/)
- jsDelivr [http://www.jsdelivr.com/projects/docsify](http://www.jsdelivr.com/projects/docsify) - jsDelivr [http://www.jsdelivr.com/projects/docsify](http://www.jsdelivr.com/projects/docsify)
### Cover Page
Through the markdown can generate a cover page. create a `_coverpage.md` and set `data-coverpage` in script tag.
```markdown
![logo](_media/icon.svg)
# docsify <small>1.2.0</small>
> A magical documentation site generator.
- Simple and lightweight (~12kb gzipped)
- Multiple themes
- Not build static html files
[GitHub](https://github.com/QingWei-Li/docsify/)
[Get Started](#quick-start)
```
### Options ### Options
#### repo #### repo
@ -261,3 +270,14 @@ If your HTML entry file and the markdown files are in different directories, we
<!-- Even if the docs is on another site 😄 --> <!-- Even if the docs is on another site 😄 -->
<script src="/lib/docsify.js" data-base-path="https://docsify.js.org/"></script> <script src="/lib/docsify.js" data-base-path="https://docsify.js.org/"></script>
``` ```
#### coverpage
Generate cover page.
```html
<script src="/lib/docsify.js" data-coverpage></script>
<!-- or -->
<script src="/lib/docsify.js" data-coverpage="other.md"></script>
```

13
docs/_coverpage.md Normal file
View File

@ -0,0 +1,13 @@
![logo](_media/icon.svg)
# docsify <small>1.2.0</small>
> A magical documentation site generator.
- Simple and lightweight (~12kb gzipped)
- Multiple themes
- Not build static html files
[GitHub](https://github.com/QingWei-Li/docsify/)
[Get Started](#quick-start)

30
docs/_media/icon.svg Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="122px" height="94px" viewBox="0 0 122 94" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 41.2 (35397) - http://www.bohemiancoding.com/sketch -->
<title>icon</title>
<desc>Created with Sketch.</desc>
<defs>
<path d="M144.453286,104 C177.038086,104 203.453286,77.5848002 203.453286,45 C203.453286,12.4151998 177.038086,-14 144.453286,-14 C111.868486,-14 114.603207,13.6754846 114.603207,46.2602848 C114.603207,78.845085 111.868486,104 144.453286,104 Z" id="path-1"></path>
<filter x="-50%" y="-50%" width="200%" height="200%" filterUnits="objectBoundingBox" id="filter-2">
<feOffset dx="7" dy="-10" in="SourceAlpha" result="shadowOffsetInner1"></feOffset>
<feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
</filter>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="icon" transform="translate(-98.000000, 2.000000)">
<g id="body" transform="translate(159.000000, 45.000000) rotate(-90.000000) translate(-159.000000, -45.000000) ">
<use fill="#2ECE53" fill-rule="evenodd" xlink:href="#path-1"></use>
<use fill="black" fill-opacity="1" filter="url(#filter-2)" xlink:href="#path-1"></use>
<use stroke="#0E1320" stroke-width="4" xlink:href="#path-1"></use>
</g>
<circle id="left-eye" fill="#000000" cx="139" cy="38" r="7"></circle>
<circle id="right-eye" fill="#000000" cx="183" cy="38" r="7"></circle>
<g id="light" transform="translate(112.000000, 10.000000)" fill="#FFFFFF">
<circle cx="2" cy="28" r="2"></circle>
<path d="M12.2551528,-1.65016666 C12.1154537,-2.17684986 12.4455583,-2.60381096 13.011574,-2.60381096 L14.9928363,-2.60381096 C15.5502953,-2.60381096 16.1214654,-2.16566487 16.2594657,-1.64268776 C16.2594657,-1.64268776 17.4280152,2.48668594 17.9030739,6.45786647 C18.3781327,10.429047 18.3171359,10.4652901 18.3171359,12.1782569 C18.3171359,16.9413523 16.2076398,26.4389164 16.2076398,26.4389164 C16.0941814,26.9676035 15.558852,27.396189 14.9928363,27.396189 L13.011574,27.396189 C12.454115,27.396189 12.1166642,26.9691757 12.2568366,26.4301177 C12.2568366,26.4301177 13.4260575,22.2288768 13.9640759,17.9859148 C14.5020943,13.7429529 14.309594,15.2982629 14.5626609,12.3723978 C14.9355337,8.06138047 12.2551528,-1.65016666 12.2551528,-1.65016666 Z" id="light-line" transform="translate(15.271433, 12.396189) scale(-1, 1) rotate(-48.000000) translate(-15.271433, -12.396189) "></path>
</g>
<path d="M159.5,78.3050108 C169.164983,78.3050108 177,70.4699939 177,60.8050108 C177,51.1400277 169.688728,56.4616841 160.023745,56.4616841 C150.358762,56.4616841 142,51.1400277 142,60.8050108 C142,70.4699939 149.835017,78.3050108 159.5,78.3050108 Z" id="mouth" fill="#000000"></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -17,8 +17,8 @@
</body> </body>
<script <script
src="//cdn.jsdelivr.net/docsify/latest/lib/docsify.min.js" src="//cdn.jsdelivr.net/docsify/latest/lib/docsify.min.js"
data-repo="qingwei-li/docsify" data-max-level="4"
data-max-level="3"
data-sidebar-toggle data-sidebar-toggle
data-coverpage
data-router></script> data-router></script>
</html> </html>

View File

@ -1,10 +1,3 @@
<p align="center">
<img alt="docsify" src="https://cloud.githubusercontent.com/assets/7565692/21292094/5c206de4-c533-11e6-9493-29ea67b01dde.png">
</p>
<p align="center">
无需构建快速生成文档页
</p>
## 特性 ## 特性
- 无需构建,写完 markdown 直接发布 - 无需构建,写完 markdown 直接发布
@ -106,6 +99,28 @@ docsify serve docs
- UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/) - UNPKG [https://unpkg.com/docsify/](https://unpkg.com/docsify/)
- jsDelivr [http://www.jsdelivr.com/projects/docsify](http://www.jsdelivr.com/projects/docsify) - jsDelivr [http://www.jsdelivr.com/projects/docsify](http://www.jsdelivr.com/projects/docsify)
### 封面
只需要写几行简单的 markdown 就可以拥有一页精致的封面,通过添加 `data-coverpage` 属性,并创建 `_coverpage.md`,按照下面的格式书写即可。
```markdown
![logo](_media/icon.svg)
# docsify <small>1.2.0</small>
> A magical documentation site generator.
- Simple and lightweight (~12kb gzipped)
- Multiple themes
- Not build static html files
[GitHub](https://github.com/QingWei-Li/docsify/)
[Get Started](#quick-start)
```
### 配置参数 ### 配置参数
#### repo #### repo
@ -258,3 +273,14 @@ Sidebar 开关按钮
<!-- 甚至文档是在其他站点下 😄 --> <!-- 甚至文档是在其他站点下 😄 -->
<script src="/lib/docsify.js" data-base-path="https://docsify.js.org/"></script> <script src="/lib/docsify.js" data-base-path="https://docsify.js.org/"></script>
``` ```
#### coverpage
生成封面,参考 [#封面](#封面).
```html
<script src="/lib/docsify.js" data-coverpage></script>
<!-- or -->
<script src="/lib/docsify.js" data-coverpage="other.md"></script>
```

View File

@ -23,11 +23,11 @@ export function scrollActiveSidebar () {
function highlight () { function highlight () {
for (let i = 0, len = anchors.length; i < len; i += 1) { for (let i = 0, len = anchors.length; i < len; i += 1) {
const node = anchors[i].parentNode const node = anchors[i]
const bcr = node.getBoundingClientRect() const bcr = node.getBoundingClientRect()
if (bcr.top < 10 && bcr.bottom > 10) { if (bcr.top < 10 && bcr.bottom > 10) {
const li = nav[node.id] const li = nav[node.getAttribute('data-id')]
if (!li || li === active) return if (!li || li === active) return
if (active) active.setAttribute('class', '') if (active) active.setAttribute('class', '')
@ -40,9 +40,8 @@ export function scrollActiveSidebar () {
} }
} }
const dom = document.querySelector('main .content') window.removeEventListener('scroll', highlight)
dom.removeEventListener('scroll', highlight) window.addEventListener('scroll', highlight)
dom.addEventListener('scroll', highlight)
highlight() highlight()
} }
@ -100,3 +99,16 @@ export function scroll2Top () {
} }
cacheContentDOM.scrollTop = 0 cacheContentDOM.scrollTop = 0
} }
export function sticky () {
const dom = document.querySelector('section.cover')
const coverHeight = dom.getBoundingClientRect().height
return (function () {
if (window.pageYOffset >= coverHeight || dom.classList.contains('hidden')) {
document.body.classList.add('sticky')
} else {
document.body.classList.remove('sticky')
}
})()
}

View File

@ -1,5 +1,5 @@
import { load, camel2kebab, isNil, getRoute } from './util' import { load, camel2kebab, isNil, getRoute } from './util'
import { activeLink, scrollIntoView } from './event' import { activeLink, scrollIntoView, sticky } from './event'
import * as render from './render' import * as render from './render'
const OPTIONS = { const OPTIONS = {
@ -12,6 +12,7 @@ const OPTIONS = {
loadNavbar: null, loadNavbar: null,
router: false, router: false,
homepage: 'README.md', homepage: 'README.md',
coverpage: '',
basePath: '', basePath: '',
auto2top: false auto2top: false
} }
@ -25,6 +26,7 @@ if (script) {
} }
if (OPTIONS.loadSidebar === true) OPTIONS.loadSidebar = '_sidebar.md' if (OPTIONS.loadSidebar === true) OPTIONS.loadSidebar = '_sidebar.md'
if (OPTIONS.loadNavbar === true) OPTIONS.loadNavbar = '_navbar.md' if (OPTIONS.loadNavbar === true) OPTIONS.loadNavbar = '_navbar.md'
if (OPTIONS.coverpage === true) OPTIONS.coverpage = '_coverpage.md'
if (OPTIONS.sidebar) OPTIONS.sidebar = window[OPTIONS.sidebar] if (OPTIONS.sidebar) OPTIONS.sidebar = window[OPTIONS.sidebar]
} }
@ -56,6 +58,15 @@ const mainRender = function (cb) {
page = `${route}.md` page = `${route}.md`
} }
// Render Cover page
if (OPTIONS.coverpage) {
if (page === OPTIONS.homepage) {
load(OPTIONS.coverpage).then(render.renderCover)
} else {
render.renderCover()
}
}
cacheXhr && cacheXhr.abort && cacheXhr.abort() cacheXhr && cacheXhr.abort && cacheXhr.abort()
// Render markdown file // Render markdown file
cacheXhr = load(page, 'GET', render.renderLoading) cacheXhr = load(page, 'GET', render.renderLoading)
@ -91,6 +102,7 @@ const Docsify = function () {
mainRender(_ => { mainRender(_ => {
activeLink('aside.sidebar', true) activeLink('aside.sidebar', true)
scrollIntoView() scrollIntoView()
OPTIONS.coverpage && sticky()
}) })
} }

View File

@ -1,8 +1,8 @@
import marked from 'marked' import marked from 'marked'
import Prism from 'prismjs' import Prism from 'prismjs'
import * as tpl from './tpl' import * as tpl from './tpl'
import { activeLink, scrollActiveSidebar, bindToggle, scroll2Top } from './event' import { activeLink, scrollActiveSidebar, bindToggle, scroll2Top, sticky } from './event'
import { genTree, getRoute } from './util' import { genTree, getRoute, isMobile } from './util'
let OPTIONS = {} let OPTIONS = {}
const CACHE = {} const CACHE = {}
@ -32,7 +32,7 @@ renderer.heading = function (text, level) {
toc.push({ level, slug: `${route}#${encodeURIComponent(slug)}`, title: text }) toc.push({ level, slug: `${route}#${encodeURIComponent(slug)}`, title: text })
return `<h${level} id="${slug}"><a href="${route}#${slug}" class="anchor"></a>${text}</h${level}>` return `<a href="${route}#${slug}" data-id="${slug}" class="anchor"><h${level} id="${slug}">${text}</h${level}></a>`
} }
// highlight code // highlight code
renderer.code = function (code, lang = '') { renderer.code = function (code, lang = '') {
@ -55,11 +55,21 @@ marked.setOptions({ renderer })
export function renderApp (dom, replace) { export function renderApp (dom, replace) {
const nav = document.querySelector('nav') || document.createElement('nav') const nav = document.querySelector('nav') || document.createElement('nav')
dom[replace ? 'outerHTML' : 'innerHTML'] = tpl.toggle(OPTIONS.sidebarToggle) + tpl.corner(OPTIONS.repo) + tpl.main() if (!OPTIONS.repo) nav.classList.add('no-badge')
dom[replace ? 'outerHTML' : 'innerHTML'] = tpl.corner(OPTIONS.repo) +
(OPTIONS.coverpage ? tpl.cover() : '') +
tpl.main(OPTIONS.sidebarToggle ? tpl.toggle() : '')
document.body.insertBefore(nav, document.body.children[0]) document.body.insertBefore(nav, document.body.children[0])
// bind toggle // bind toggle
bindToggle('button.sidebar-toggle') bindToggle('button.sidebar-toggle')
// bind sticky effect
if (OPTIONS.coverpage) {
!isMobile() && window.addEventListener('scroll', sticky)
} else {
document.body.classList.add('sticky')
}
} }
/** /**
@ -110,6 +120,20 @@ export function renderSidebar (content) {
toc = [] toc = []
} }
/**
* Cover Page
*/
export function renderCover (content) {
renderCover.dom = renderCover.dom || document.querySelector('section.cover')
if (!content) {
renderCover.dom.classList.add('hidden')
} else {
renderCover.dom.classList.remove('hidden')
!renderCover.rendered && renderTo('.cover-main', marked(content))
renderCover.rendered = true
}
}
/** /**
* render loading bar * render loading bar
* @return {[type]} [description] * @return {[type]} [description]

View File

@ -0,0 +1,82 @@
section.cover {
&.hidden {
display: none;
}
height: 100vh;
position: relative;
.cover-main {
position: absolute 0 0 0 0;
padding: 20vh 0;
text-align: center;
margin: 0 16px;
}
a {
color: inherit;
text-decoration: none;
&:hover {
text-decoration: none;
}
}
h1 {
text-align: center;
font-size: 2.5rem;
position: relative;
margin: .625rem 0 2.5rem;
font-weight: 300;
color: inherit;
small {
position: absolute;
bottom: -.4375rem;
font-size: 1rem;
}
}
blockquote {
text-align: center;
font-size: 1.5rem;
}
ul {
max-width: 500px;
list-style-type: none;
margin: 1em auto;
padding: 0;
line-height: 1.8;
}
p a {
margin-top: 1em;
border-radius: 2em;
border: 1px solid $color-primary;
box-sizing: border-box;
color: $color-primary;
font-size: 1.05em;
letter-spacing: 0.1em;
padding: 0.75em 2em;
text-decoration: none;
transition: all 0.15s ease;
margin-right: 1em;
display: inline-block;
&:last-child {
margin-right: 0;
background-color: $color-primary;
color: #fff;
&:hover {
opacity: .8;
color: inherit;
}
}
&:hover {
color: inherit;
}
}
}

View File

@ -1,4 +1,3 @@
* { * {
box-sizing: border-box; box-sizing: border-box;
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
@ -38,6 +37,17 @@ img {
max-width: 100%; max-width: 100%;
} }
kbd {
display: inline-block;
padding: 3px 5px;
margin-bottom : 3px;
font-size: 12px !important;
line-height: 12px;
vertical-align: middle;
border: solid 1px #ccc;
border-radius: 3px;
}
/* navbar */ /* navbar */
nav { nav {
position: absolute; position: absolute;
@ -47,6 +57,10 @@ nav {
margin: 25px 60px 0 0; margin: 25px 60px 0 0;
text-align: right; text-align: right;
&.no-badge {
margin-right: 25px;
}
p { p {
margin: 0; margin: 0;
} }
@ -124,18 +138,13 @@ nav {
/* github corner */ /* github corner */
.github-corner { .github-corner {
position: absolute; position: fixed;
top: 0; top: 0;
right: 0; right: 0;
z-index: 1; z-index: 1;
text-decoration: none; text-decoration: none;
border-bottom: 0; border-bottom: 0;
&:hover {
background-color: inherit;
color: inherit;
}
&:hover .octo-arm { &:hover .octo-arm {
animation:octocat-wave 560ms ease-in-out; animation:octocat-wave 560ms ease-in-out;
} }
@ -154,6 +163,16 @@ main {
position: relative; position: relative;
} }
.anchor {
text-decoration: none;
transition: all .3s;
display: block;
&:hover {
text-decoration: underline;
}
}
/* sidebar */ /* sidebar */
.sidebar { .sidebar {
border-right: 1px solid rgba(0, 0, 0, .07); border-right: 1px solid rgba(0, 0, 0, .07);
@ -209,11 +228,15 @@ main {
} }
} }
body.sticky {
.sidebar, .sidebar-toggle {
position: fixed;
}
}
/* main content */ /* main content */
.content { .content {
overflow-y: auto;
position: absolute 0 0 0 $sidebar-width; position: absolute 0 0 0 $sidebar-width;
overflow-x: hidden;
padding-top: 20px; padding-top: 20px;
transition: left 250ms ease; transition: left 250ms ease;
} }
@ -278,7 +301,6 @@ body.close {
} }
nav { nav {
position: static;
margin-top: 16px; margin-top: 16px;
} }
@ -295,8 +317,6 @@ body.close {
left: 0; left: 0;
min-width: 100vw; min-width: 100vw;
transition: transform 250ms ease; transition: transform 250ms ease;
position: static;
overflow-y: auto;
} }
nav, .github-corner { nav, .github-corner {

View File

@ -4,6 +4,7 @@ $color-primary: #0074D9;
$sidebar-width: 16em; $sidebar-width: 16em;
@import "basic/layout"; @import "basic/layout";
@import "basic/coverpage";
body { body {
color: #34495e; color: #34495e;
@ -11,6 +12,7 @@ body {
/* sidebar */ /* sidebar */
.sidebar { .sidebar {
color: #364149; color: #364149;
background-color: #fff;
a { a {
color: #666; color: #666;

View File

@ -4,6 +4,7 @@ $color-primary: #42b983;
$sidebar-width: 300px; $sidebar-width: 300px;
@import "basic/layout"; @import "basic/layout";
@import "basic/coverpage";
body { body {
background-color: #fff; background-color: #fff;
@ -13,6 +14,7 @@ body {
/* sidebar */ /* sidebar */
.sidebar { .sidebar {
color: #364149; color: #364149;
background-color: #fff;
li { li {
margin: 6px 15px; margin: 6px 15px;

View File

@ -21,10 +21,10 @@ export function corner (data) {
/** /**
* Render main content * Render main content
* @return {[type]} [description]
*/ */
export function main () { export function main (tpl) {
return `<main> return `<main>
${tpl}
<aside class="sidebar"></aside> <aside class="sidebar"></aside>
<section class="content"> <section class="content">
<article class="markdown-section"></article> <article class="markdown-section"></article>
@ -32,8 +32,19 @@ export function main () {
</main>` </main>`
} }
export function toggle (bool) { /**
if (!bool) return '' * Cover Page
*/
export function cover () {
const SL = ', 100%, 85%'
const bgc = `linear-gradient(to left bottom, hsl(${Math.floor(Math.random() * 255) + SL}) 0%, hsl(${Math.floor(Math.random() * 255) + SL}) 100%)`
return `<section class="cover" style="background: ${bgc}">
<div class="cover-main"></div>
</section>`
}
export function toggle () {
return `<button class="sidebar-toggle"> return `<button class="sidebar-toggle">
<span></span><span></span><span></span> <span></span><span></span><span></span>
</button>` </button>`