Skip to content

Commit 6dea685

Browse files
committed
feat: init ocsify-server-renderer
1 parent f095eb8 commit 6dea685

File tree

8 files changed

+124
-7
lines changed

8 files changed

+124
-7
lines changed

build/build-ssr.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var rollup = require('rollup')
2+
var buble = require('rollup-plugin-buble')
3+
var commonjs = require('rollup-plugin-commonjs')
4+
var isProd = process.argv[process.argv.length - 1] !== '--dev'
5+
6+
rollup
7+
.rollup({
8+
entry: 'packages/docsify-server-renderer/index.js',
9+
plugins: [
10+
buble(),
11+
commonjs()
12+
],
13+
onwarn: function() {}
14+
})
15+
.then(function (bundle) {
16+
var dest = 'packages/docsify-server-renderer/build.js'
17+
18+
console.log(dest)
19+
bundle.write({
20+
format: 'cjs',
21+
dest: dest
22+
})
23+
})
24+
.catch(function (err) {
25+
console.error(err)
26+
})

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"build": "rm -rf lib themes && node build/build.js && mkdir lib/themes && mkdir themes && node build/build-css.js",
2424
"dev:build": "rm -rf lib themes && mkdir themes && node build/build.js --dev && node build/build-css.js --dev",
2525
"dev": "node app.js & nodemon -w src -e js,css --exec 'npm run dev:build'",
26+
"build:ssr": "node build/build-ssr",
2627
"test": "eslint src --fix"
2728
},
2829
"dependencies": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build.js
2+
node_modules
3+
*.log
4+
.git
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# docsify-server-renderer
2+
3+
## Install
4+
5+
```bash
6+
yarn add docsify-server-render
7+
```
8+
9+
## Usage
10+
11+
```js
12+
var Renderer = require('docsify-server-renderer')
13+
var readFileSync = require('fs').readFileSync
14+
var resolve = require('path').resolve
15+
16+
// init
17+
var renderer = new Renderer({
18+
template: readFileSync('./index.template.html', 'utf-8').,
19+
path: resolve(_dirname, './docs'),
20+
config: {
21+
name: 'docsify',
22+
repo: 'qingwei-li/docsify'
23+
}
24+
//,cache: () => {}
25+
})
26+
27+
renderer.renderToString({ url })
28+
.then(html => {})
29+
.catch(err => {})
30+
```
31+
32+
*index.template.html*
33+
34+
```html
35+
<!DOCTYPE html>
36+
<html lang="en">
37+
<head>
38+
<meta charset="UTF-8">
39+
<title>docsify</title>
40+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
41+
<link rel="stylesheet" href="//unpkg.com/docsify/themes/buble.css" title="buble" disabled>
42+
</head>
43+
<body>
44+
<div id="app"></div>
45+
<!--inject-docsify-config-->
46+
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
47+
</body>
48+
</html>
49+
```
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Compiler } from '../../src/core/render/compiler'
2+
import { AbstractHistory } from '../../src/core/router/history/abstract'
3+
import path from 'path'
4+
import fs from 'fs'
5+
6+
export default class Renderer {
7+
constructor ({
8+
template,
9+
path,
10+
config,
11+
cache
12+
}) {
13+
this.template = template
14+
this.path = path
15+
this.config = config
16+
this.cache = cache
17+
18+
this.router = new AbstractHistory()
19+
this.compiler = new Compiler(config, this.router)
20+
}
21+
22+
renderToString(url) {
23+
console.log(url)
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "docsify-server-renderer",
3+
"version": "4.0.0",
4+
"description": "docsify server renderer",
5+
"author": {
6+
"name": "qingwei-li",
7+
"email": "cinwell.li@gmail.com",
8+
"url": "https://github.com/QingWei-Li"
9+
},
10+
"homepage": "https://docsify.js.org",
11+
"license": "MIT",
12+
"repository": "QingWei-Li/docsify",
13+
"main": "build.js",
14+
"scripts": {
15+
"test": "echo 'hello'"
16+
}
17+
}

src/core/router/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { AbstractHistory } from './history/abstract'
21
import { HashHistory } from './history/hash'
32
import { HTML5History } from './history/html5'
4-
import { supportsPushState, inBrowser } from '../util/env'
3+
import { supportsPushState } from '../util/env'
54

65
export function routerMixin (proto) {
76
proto.route = {}
@@ -16,8 +15,6 @@ export function initRouter (vm) {
1615

1716
if (mode === 'history' && supportsPushState) {
1817
router = new HTML5History(config)
19-
} else if (!inBrowser || mode === 'abstract') {
20-
router = new AbstractHistory(config)
2118
} else {
2219
router = new HashHistory(config)
2320
}

src/core/util/env.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ export const isIE = UA && /msie|trident/.test(UA)
44

55
export const isMobile = document.body.clientWidth <= 600
66

7-
export const inBrowser = typeof window !== 'undefined'
8-
97
/**
108
* @see https://github.com/MoOx/pjax/blob/master/lib/is-supported.js
119
*/
12-
export const supportsPushState = inBrowser && (function () {
10+
export const supportsPushState = (function () {
1311
// Borrowed wholesale from https://github.com/defunkt/jquery-pjax
1412
return window.history &&
1513
window.history.pushState &&

0 commit comments

Comments
 (0)