mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-11-29 18:48:14 +08:00
first commit
This commit is contained in:
commit
44ac51b9c2
6
.eslintrc
Normal file
6
.eslintrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": ["vue"],
|
||||
"globals": {
|
||||
"XMLHttpRequest": true
|
||||
}
|
||||
}
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*.log
|
||||
node_modules
|
||||
yarn.lock
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 cinwell.li
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
33
README.md
Normal file
33
README.md
Normal file
@ -0,0 +1,33 @@
|
||||
# docsify
|
||||
[![Build Status](https://travis-ci.org/QingWei-Li/docsify.svg?branch=master)](https://travis-ci.org/QingWei-Li/docsify)
|
||||
[![Coverage Status](https://coveralls.io/repos/github/QingWei-Li/docsify/badge.svg?branch=master)](https://coveralls.io/github/QingWei-Li/docsify?branch=master)
|
||||
[![npm](https://img.shields.io/npm/v/docsify.svg)](https://www.npmjs.com/package/docsify)
|
||||
|
||||
>🃏 A magical documentation site generator.
|
||||
|
||||
## Features
|
||||
- Easy and lightweight
|
||||
- Custom themes and plugins
|
||||
|
||||
## Quick start
|
||||
Such as [./docs](./docs), Just create `404.html` and `README.md` into `/docs`.
|
||||
|
||||
404.html
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
|
||||
</head>
|
||||
<body></body>
|
||||
<script src="//unpkg.com/marked/marked.min.js"></script>
|
||||
<script src="//unpkg.com/highlight.js/lib/highlight.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
</html>
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
MIT
|
12
docs/404.html
Normal file
12
docs/404.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>docsify</title>
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
|
||||
</head>
|
||||
<body></body>
|
||||
<script src="//unpkg.com/marked/marked.min.js"></script>
|
||||
<script src="//unpkg.com/highlight.js/lib/highlight.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
|
||||
</html>
|
1
docs/README.md
Normal file
1
docs/README.md
Normal file
@ -0,0 +1 @@
|
||||
# ahhh
|
82
lib/docsify.js
Normal file
82
lib/docsify.js
Normal file
@ -0,0 +1,82 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('marked'), require('prismjs')) :
|
||||
typeof define === 'function' && define.amd ? define(['marked', 'prismjs'], factory) :
|
||||
(global.Docsify = factory(global.marked,global.Prism));
|
||||
}(this, (function (marked,Prism) { 'use strict';
|
||||
|
||||
marked = 'default' in marked ? marked['default'] : marked;
|
||||
Prism = 'default' in Prism ? Prism['default'] : Prism;
|
||||
|
||||
var ajax = function (url, options) {
|
||||
if ( options === void 0 ) options = {};
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open(options.method || 'get', url);
|
||||
xhr.send();
|
||||
|
||||
return {
|
||||
then: function (cb) { return xhr.addEventListener('load', cb); }
|
||||
}
|
||||
};
|
||||
|
||||
var renderer = new marked.Renderer();
|
||||
|
||||
/**
|
||||
* render anchor tag
|
||||
* @link https://github.com/chjj/marked#overriding-renderer-methods
|
||||
*/
|
||||
renderer.heading = function (text, level) {
|
||||
var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
|
||||
|
||||
return '<h' + level + '><a name="' + escapedText + '" class="anchor" href="#' +
|
||||
escapedText + '"><span class="header-link"></span></a>' + text +
|
||||
'</h' + level + '>'
|
||||
};
|
||||
|
||||
marked.setOptions({
|
||||
highlight: function highlight (code, lang) {
|
||||
return Prism.highlight(code, Prism.languages[lang])
|
||||
}
|
||||
});
|
||||
|
||||
var render = function (content) {
|
||||
return marked(content, { renderer: renderer })
|
||||
};
|
||||
|
||||
var Docsify = function Docsify (opts) {
|
||||
if ( opts === void 0 ) opts = {};
|
||||
|
||||
Docsify.installed = true;
|
||||
|
||||
this.dom = document.querySelector(opts.el || 'body');
|
||||
this.loc = document.location.pathname;
|
||||
this.loc = this.loc === '/' ? 'README' : this.loc;
|
||||
this.load();
|
||||
};
|
||||
|
||||
Docsify.prototype.load = function load () {
|
||||
var this$1 = this;
|
||||
|
||||
ajax(((this.loc) + ".md")).then(function (res) {
|
||||
var target = res.target;
|
||||
if (target.status >= 400) {
|
||||
this$1.render('not found');
|
||||
} else {
|
||||
this$1.render(res.target.response);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Docsify.prototype.render = function render$1 (content) {
|
||||
this.dom.innerHTML = render(content);
|
||||
};
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
if (Docsify.installed) { return }
|
||||
new Docsify();
|
||||
});
|
||||
|
||||
return Docsify;
|
||||
|
||||
})));
|
1
lib/docsify.min.js
vendored
Normal file
1
lib/docsify.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory(require("marked"),require("highlight.js")):typeof define==="function"&&define.amd?define(["marked","highlight.js"],factory):global.Docsify=factory(global.marked,global.hljs)})(this,function(marked,hljs){"use strict";marked="default"in marked?marked["default"]:marked;hljs="default"in hljs?hljs["default"]:hljs;var ajax=function(url,options){if(options===void 0)options={};var xhr=new XMLHttpRequest;xhr.open(options.method||"get",url);xhr.send();return{then:function(cb){return xhr.addEventListener("load",cb)},catch:function(cb){return xhr.addEventListener("error",cb)}}};var renderer=new marked.Renderer;renderer.heading=function(text,level){var escapedText=text.toLowerCase().replace(/[^\w]+/g,"-");return"<h"+level+'><a name="'+escapedText+'" class="anchor" href="#'+escapedText+'"><span class="header-link"></span></a>'+text+"</h"+level+">"};var render=function(content){return marked(content,{renderer:renderer,highlight:function highlight(code){return hljs.highlightAuto(code).value}})};var Docsify=function Docsify(opts){if(opts===void 0)opts={};Docsify.installed=true;this.dom=document.querySelector(opts.el||"body");var loc="https://yanagieiichi.github.io/reciper/intro/README.md";this.load(loc)};Docsify.prototype.load=function load(loc){var this$1=this;ajax(""+loc).then(function(res){this$1.render(res.target.response)})};Docsify.prototype.render=function render$1(content){this.dom.innerHTML=render(content)};window.addEventListener("load",function(){if(Docsify.installed){return}new Docsify});return Docsify});
|
38
package.json
Normal file
38
package.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "docsify",
|
||||
"version": "0.0.0",
|
||||
"description": "A magical documentation generator.",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"lib",
|
||||
"themes"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rollup -c && uglifyjs lib/docsify.js -o lib/docsify.min.js",
|
||||
"dev": "nodemon -w src -x 'rollup -c && node test/server.js'",
|
||||
"test": "eslint src server"
|
||||
},
|
||||
"keywords": [
|
||||
"doc",
|
||||
"docs",
|
||||
"documentation",
|
||||
"creator",
|
||||
"generator"
|
||||
],
|
||||
"author": "qingwei-li <cinwell.li@gmail.com> (https://github.com/QingWei-Li)",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"buffet": "^1.0.10",
|
||||
"eslint": "^3.10.2",
|
||||
"eslint-config-vue": "^2.0.1",
|
||||
"eslint-plugin-vue": "^1.0.0",
|
||||
"nodemon": "^1.11.0",
|
||||
"rollup": "^0.36.3",
|
||||
"rollup-plugin-buble": "^0.14.0",
|
||||
"uglify-js": "^2.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"marked": "^0.3.6",
|
||||
"prismjs": "^1.5.1"
|
||||
}
|
||||
}
|
13
rollup.config.js
Normal file
13
rollup.config.js
Normal file
@ -0,0 +1,13 @@
|
||||
import buble from 'rollup-plugin-buble'
|
||||
|
||||
export default {
|
||||
entry: 'src/index.js',
|
||||
dest: 'lib/docsify.js',
|
||||
plugins: [buble()],
|
||||
globals: {
|
||||
marked: 'marked',
|
||||
prismjs: 'Prism'
|
||||
},
|
||||
format: 'umd',
|
||||
moduleName: 'Docsify'
|
||||
}
|
10
src/ajax.js
Normal file
10
src/ajax.js
Normal file
@ -0,0 +1,10 @@
|
||||
export default function (url, options = {}) {
|
||||
const xhr = new XMLHttpRequest()
|
||||
|
||||
xhr.open(options.method || 'get', url)
|
||||
xhr.send()
|
||||
|
||||
return {
|
||||
then: cb => xhr.addEventListener('load', cb)
|
||||
}
|
||||
}
|
35
src/index.js
Normal file
35
src/index.js
Normal file
@ -0,0 +1,35 @@
|
||||
import ajax from './ajax'
|
||||
import render from './render'
|
||||
|
||||
class Docsify {
|
||||
constructor (opts = {}) {
|
||||
Docsify.installed = true
|
||||
|
||||
this.dom = document.querySelector(opts.el || 'body')
|
||||
this.loc = document.location.pathname
|
||||
this.loc = this.loc === '/' ? 'README' : this.loc
|
||||
this.load()
|
||||
}
|
||||
|
||||
load () {
|
||||
ajax(`${this.loc}.md`).then(res => {
|
||||
const target = res.target
|
||||
if (target.status >= 400) {
|
||||
this.render('not found')
|
||||
} else {
|
||||
this.render(res.target.response)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render (content) {
|
||||
this.dom.innerHTML = render(content)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
if (Docsify.installed) return
|
||||
new Docsify()
|
||||
})
|
||||
|
||||
export default Docsify
|
26
src/render.js
Normal file
26
src/render.js
Normal file
@ -0,0 +1,26 @@
|
||||
import marked from 'marked'
|
||||
import Prism from 'prismjs'
|
||||
|
||||
const renderer = new marked.Renderer()
|
||||
|
||||
/**
|
||||
* render anchor tag
|
||||
* @link https://github.com/chjj/marked#overriding-renderer-methods
|
||||
*/
|
||||
renderer.heading = function (text, level) {
|
||||
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-')
|
||||
|
||||
return '<h' + level + '><a name="' + escapedText + '" class="anchor" href="#' +
|
||||
escapedText + '"><span class="header-link"></span></a>' + text +
|
||||
'</h' + level + '>'
|
||||
}
|
||||
|
||||
marked.setOptions({
|
||||
highlight (code, lang) {
|
||||
return Prism.highlight(code, Prism.languages[lang])
|
||||
}
|
||||
})
|
||||
|
||||
export default function (content) {
|
||||
return marked(content, { renderer })
|
||||
}
|
12
test/404.html
Normal file
12
test/404.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>docsify</title>
|
||||
<link rel="stylesheet" href="themes/vue.css">
|
||||
</head>
|
||||
<body></body>
|
||||
<script src="//unpkg.com/marked/marked.min.js"></script>
|
||||
<script src="//unpkg.com/prismjs/prism.js"></script>
|
||||
<script src="docsify.js"></script>
|
||||
</html>
|
27
test/README.md
Normal file
27
test/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# docsify
|
||||
> A magical documentation generator.
|
||||
|
||||
## Usage
|
||||
Create `404.html` into `/docs`
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
|
||||
</head>
|
||||
<body></body>
|
||||
<script src="//unpkg.com/marked/marked.min.js"></script>
|
||||
<script src="//unpkg.com/highlight.js/lib/highlight.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
</html>
|
||||
```
|
||||
|
||||
```javascript
|
||||
var a = require('a')
|
||||
console.log(a)
|
||||
```
|
||||
|
||||
## License
|
||||
MIT
|
1
test/docsify.js
Symbolic link
1
test/docsify.js
Symbolic link
@ -0,0 +1 @@
|
||||
../lib/docsify.js
|
8
test/server.js
Normal file
8
test/server.js
Normal file
@ -0,0 +1,8 @@
|
||||
const server = require('http').createServer()
|
||||
const buffet = require('buffet')({ root: './test' })
|
||||
|
||||
server.on('request', buffet)
|
||||
|
||||
server.listen(6677, function () {
|
||||
console.log('Ready! Listening on http://localhost:6677')
|
||||
})
|
1
test/theme.md
Normal file
1
test/theme.md
Normal file
@ -0,0 +1 @@
|
||||
# Themes
|
1
test/themes
Symbolic link
1
test/themes
Symbolic link
@ -0,0 +1 @@
|
||||
../themes
|
0
themes/vue.css
Normal file
0
themes/vue.css
Normal file
Loading…
Reference in New Issue
Block a user