mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-11-30 02:58:37 +08:00
feat: init ocsify-server-renderer
This commit is contained in:
parent
f095eb888f
commit
6dea685fee
26
build/build-ssr.js
Normal file
26
build/build-ssr.js
Normal 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)
|
||||
})
|
@ -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": {
|
||||
|
4
packages/docsify-server-renderer/.gitignore
vendored
Normal file
4
packages/docsify-server-renderer/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build.js
|
||||
node_modules
|
||||
*.log
|
||||
.git
|
49
packages/docsify-server-renderer/README.md
Normal file
49
packages/docsify-server-renderer/README.md
Normal 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>
|
||||
```
|
25
packages/docsify-server-renderer/index.js
Normal file
25
packages/docsify-server-renderer/index.js
Normal 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)
|
||||
}
|
||||
}
|
17
packages/docsify-server-renderer/package.json
Normal file
17
packages/docsify-server-renderer/package.json
Normal 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'"
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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 &&
|
||||
|
Loading…
Reference in New Issue
Block a user