diff --git a/build/build-ssr.js b/build/build-ssr.js
new file mode 100644
index 000000000..ef789c4b9
--- /dev/null
+++ b/build/build-ssr.js
@@ -0,0 +1,26 @@
+var rollup = require('rollup')
+var buble = require('rollup-plugin-buble')
+var commonjs = require('rollup-plugin-commonjs')
+var isProd = process.argv[process.argv.length - 1] !== '--dev'
+
+rollup
+ .rollup({
+ entry: 'packages/docsify-server-renderer/index.js',
+ plugins: [
+ buble(),
+ commonjs()
+ ],
+ onwarn: function() {}
+ })
+ .then(function (bundle) {
+ var dest = 'packages/docsify-server-renderer/build.js'
+
+ console.log(dest)
+ bundle.write({
+ format: 'cjs',
+ dest: dest
+ })
+ })
+ .catch(function (err) {
+ console.error(err)
+ })
diff --git a/package.json b/package.json
index 5d836f0e6..775600067 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"build": "rm -rf lib themes && node build/build.js && mkdir lib/themes && mkdir themes && node build/build-css.js",
"dev:build": "rm -rf lib themes && mkdir themes && node build/build.js --dev && node build/build-css.js --dev",
"dev": "node app.js & nodemon -w src -e js,css --exec 'npm run dev:build'",
+ "build:ssr": "node build/build-ssr",
"test": "eslint src --fix"
},
"dependencies": {
diff --git a/packages/docsify-server-renderer/.gitignore b/packages/docsify-server-renderer/.gitignore
new file mode 100644
index 000000000..28fee00cc
--- /dev/null
+++ b/packages/docsify-server-renderer/.gitignore
@@ -0,0 +1,4 @@
+build.js
+node_modules
+*.log
+.git
diff --git a/packages/docsify-server-renderer/README.md b/packages/docsify-server-renderer/README.md
new file mode 100644
index 000000000..0217ac072
--- /dev/null
+++ b/packages/docsify-server-renderer/README.md
@@ -0,0 +1,49 @@
+# docsify-server-renderer
+
+## Install
+
+```bash
+yarn add docsify-server-render
+```
+
+## Usage
+
+```js
+var Renderer = require('docsify-server-renderer')
+var readFileSync = require('fs').readFileSync
+var resolve = require('path').resolve
+
+// init
+var renderer = new Renderer({
+ template: readFileSync('./index.template.html', 'utf-8').,
+ path: resolve(_dirname, './docs'),
+ config: {
+ name: 'docsify',
+ repo: 'qingwei-li/docsify'
+ }
+ //,cache: () => {}
+})
+
+renderer.renderToString({ url })
+ .then(html => {})
+ .catch(err => {})
+```
+
+*index.template.html*
+
+```html
+
+
+
+
+ docsify
+
+
+
+
+
+
+
+
+
+```
diff --git a/packages/docsify-server-renderer/index.js b/packages/docsify-server-renderer/index.js
new file mode 100644
index 000000000..7ada4c11c
--- /dev/null
+++ b/packages/docsify-server-renderer/index.js
@@ -0,0 +1,25 @@
+import { Compiler } from '../../src/core/render/compiler'
+import { AbstractHistory } from '../../src/core/router/history/abstract'
+import path from 'path'
+import fs from 'fs'
+
+export default class Renderer {
+ constructor ({
+ template,
+ path,
+ config,
+ cache
+ }) {
+ this.template = template
+ this.path = path
+ this.config = config
+ this.cache = cache
+
+ this.router = new AbstractHistory()
+ this.compiler = new Compiler(config, this.router)
+ }
+
+ renderToString(url) {
+ console.log(url)
+ }
+}
diff --git a/packages/docsify-server-renderer/package.json b/packages/docsify-server-renderer/package.json
new file mode 100644
index 000000000..73759a9ee
--- /dev/null
+++ b/packages/docsify-server-renderer/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "docsify-server-renderer",
+ "version": "4.0.0",
+ "description": "docsify server renderer",
+ "author": {
+ "name": "qingwei-li",
+ "email": "cinwell.li@gmail.com",
+ "url": "https://github.com/QingWei-Li"
+ },
+ "homepage": "https://docsify.js.org",
+ "license": "MIT",
+ "repository": "QingWei-Li/docsify",
+ "main": "build.js",
+ "scripts": {
+ "test": "echo 'hello'"
+ }
+}
diff --git a/src/core/router/index.js b/src/core/router/index.js
index f4b991bee..145bd6d99 100644
--- a/src/core/router/index.js
+++ b/src/core/router/index.js
@@ -1,7 +1,6 @@
-import { AbstractHistory } from './history/abstract'
import { HashHistory } from './history/hash'
import { HTML5History } from './history/html5'
-import { supportsPushState, inBrowser } from '../util/env'
+import { supportsPushState } from '../util/env'
export function routerMixin (proto) {
proto.route = {}
@@ -16,8 +15,6 @@ export function initRouter (vm) {
if (mode === 'history' && supportsPushState) {
router = new HTML5History(config)
- } else if (!inBrowser || mode === 'abstract') {
- router = new AbstractHistory(config)
} else {
router = new HashHistory(config)
}
diff --git a/src/core/util/env.js b/src/core/util/env.js
index 5d143c95a..dcbcce27c 100644
--- a/src/core/util/env.js
+++ b/src/core/util/env.js
@@ -4,12 +4,10 @@ export const isIE = UA && /msie|trident/.test(UA)
export const isMobile = document.body.clientWidth <= 600
-export const inBrowser = typeof window !== 'undefined'
-
/**
* @see https://github.com/MoOx/pjax/blob/master/lib/is-supported.js
*/
-export const supportsPushState = inBrowser && (function () {
+export const supportsPushState = (function () {
// Borrowed wholesale from https://github.com/defunkt/jquery-pjax
return window.history &&
window.history.pushState &&