feat: init ocsify-server-renderer

This commit is contained in:
qingwei.li 2017-05-29 22:24:38 +08:00 committed by cinwell.li
parent f095eb888f
commit 6dea685fee
8 changed files with 124 additions and 7 deletions

26
build/build-ssr.js Normal file
View File

@ -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)
})

View File

@ -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": {

View File

@ -0,0 +1,4 @@
build.js
node_modules
*.log
.git

View File

@ -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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/buble.css" title="buble" disabled>
</head>
<body>
<div id="app"></div>
<!--inject-docsify-config-->
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
</body>
</html>
```

View File

@ -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)
}
}

View File

@ -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'"
}
}

View File

@ -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)
}

View File

@ -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 &&