Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Nov 20, 2016
0 parents commit 44ac51b
Show file tree
Hide file tree
Showing 20 changed files with 331 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["vue"],
"globals": {
"XMLHttpRequest": true
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.log
node_modules
yarn.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions docs/404.html
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ahhh
82 changes: 82 additions & 0 deletions lib/docsify.js
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions lib/docsify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (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 changes: 13 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/ajax.js
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions src/render.js
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions test/404.html
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions test/docsify.js
8 changes: 8 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions test/theme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Themes
1 change: 1 addition & 0 deletions test/themes
Empty file added themes/vue.css
Empty file.

0 comments on commit 44ac51b

Please sign in to comment.