refactor(ssr): path => context
This commit is contained in:
parent
891475e132
commit
d4f6072d10
5 changed files with 88 additions and 39 deletions
43
build/release.sh
Normal file
43
build/release.sh
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
echo "Enter new version: "
|
||||||
|
read VERSION
|
||||||
|
else
|
||||||
|
VERSION=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "Releasing $VERSION $RELEASE_TAG - are you sure? (y/n) " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
echo "Releasing $VERSION ..."
|
||||||
|
|
||||||
|
npm run lint
|
||||||
|
|
||||||
|
# build
|
||||||
|
VERSION=$VERSION npm run build
|
||||||
|
|
||||||
|
# update packages
|
||||||
|
cd packages/docsify-server-renderer
|
||||||
|
npm version $VERSION
|
||||||
|
if [[ -z $RELEASE_TAG ]]; then
|
||||||
|
npm publish
|
||||||
|
else
|
||||||
|
npm publish --tag $RELEASE_TAG
|
||||||
|
fi
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# commit
|
||||||
|
git add -A
|
||||||
|
git commit -m "[build] $VERSION"
|
||||||
|
npm version $VERSION --message "[release] $VERSION"
|
||||||
|
|
||||||
|
# publish
|
||||||
|
git push origin refs/tags/v$VERSION
|
||||||
|
git push
|
||||||
|
if [[ -z $RELEASE_TAG ]]; then
|
||||||
|
npm publish
|
||||||
|
else
|
||||||
|
npm publish --tag $RELEASE_TAG
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
@ -1,29 +1,33 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
alias: {
|
config: {
|
||||||
'/de-de/changelog': '/changelog',
|
alias: {
|
||||||
'/zh-cn/changelog': '/changelog',
|
'/de-de/changelog': '/changelog',
|
||||||
'/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
|
'/zh-cn/changelog': '/changelog',
|
||||||
},
|
'/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
|
||||||
auto2top: true,
|
|
||||||
coverpage: true,
|
|
||||||
executeScript: true,
|
|
||||||
loadSidebar: true,
|
|
||||||
loadNavbar: true,
|
|
||||||
mergeNavbar: true,
|
|
||||||
maxLevel: 4,
|
|
||||||
subMaxLevel: 2,
|
|
||||||
name: 'docsify',
|
|
||||||
search: {
|
|
||||||
noData: {
|
|
||||||
'/de-de/': 'Keine Ergebnisse!',
|
|
||||||
'/zh-cn/': '没有结果!',
|
|
||||||
'/': 'No results!'
|
|
||||||
},
|
},
|
||||||
paths: 'auto',
|
auto2top: true,
|
||||||
placeholder: {
|
coverpage: true,
|
||||||
'/de-de/': 'Suche',
|
executeScript: true,
|
||||||
'/zh-cn/': '搜索',
|
loadSidebar: true,
|
||||||
'/': 'Search'
|
loadNavbar: true,
|
||||||
|
mergeNavbar: true,
|
||||||
|
maxLevel: 4,
|
||||||
|
subMaxLevel: 2,
|
||||||
|
name: 'docsify',
|
||||||
|
search: {
|
||||||
|
noData: {
|
||||||
|
'/de-de/': 'Keine Ergebnisse!',
|
||||||
|
'/zh-cn/': '没有结果!',
|
||||||
|
'/': 'No results!'
|
||||||
|
},
|
||||||
|
paths: 'auto',
|
||||||
|
placeholder: {
|
||||||
|
'/de-de/': 'Suche',
|
||||||
|
'/zh-cn/': '搜索',
|
||||||
|
'/': 'Search'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
context: './docs',
|
||||||
|
template: './ssr.html'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
package.json
10
package.json
|
|
@ -20,15 +20,13 @@
|
||||||
"themes"
|
"themes"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf lib themes && node build/build && mkdir lib/themes && mkdir themes && node build/build-css",
|
"build": "rm -rf lib themes && node build/build && mkdir lib/themes && mkdir themes && node build/build-css && npm run build:ssr",
|
||||||
"dev:build": "rm -rf lib themes && mkdir themes && node build/build --dev && node build/build-css --dev",
|
"dev:build": "rm -rf lib themes && mkdir themes && node build/build --dev && node build/build-css --dev",
|
||||||
"dev": "node app & nodemon -w src -e js,css --exec 'npm run dev:build'",
|
"dev": "node app & nodemon -w src -e js,css --exec 'npm run dev:build'",
|
||||||
"build:ssr": "node build/build-ssr",
|
"build:ssr": "node build/build-ssr",
|
||||||
"test": "eslint {src,packages} --fix"
|
"test": "eslint {src,packages} --fix",
|
||||||
},
|
"pub:next": "RELEASE_TAG=next sh build/release",
|
||||||
"docsify": {
|
"pub": "sh build/release"
|
||||||
"path": "./",
|
|
||||||
"template": "./ssr.html"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"marked": "^0.3.6",
|
"marked": "^0.3.6",
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,15 @@ yarn add docsify-server-render
|
||||||
```js
|
```js
|
||||||
var Renderer = require('docsify-server-renderer')
|
var Renderer = require('docsify-server-renderer')
|
||||||
var readFileSync = require('fs').readFileSync
|
var readFileSync = require('fs').readFileSync
|
||||||
var resolve = require('path').resolve
|
|
||||||
|
|
||||||
// init
|
// init
|
||||||
var renderer = new Renderer({
|
var renderer = new Renderer({
|
||||||
template: readFileSync('./index.template.html', 'utf-8').,
|
template: readFileSync('./docs/index.template.html', 'utf-8').,
|
||||||
path: resolve(_dirname, './docs'),
|
context: './docs',
|
||||||
config: {
|
config: {
|
||||||
name: 'docsify',
|
name: 'docsify',
|
||||||
repo: 'qingwei-li/docsify'
|
repo: 'qingwei-li/docsify'
|
||||||
}
|
}
|
||||||
//,cache: () => {}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
renderer.renderToString({ url })
|
renderer.renderToString({ url })
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@ function mainTpl (config) {
|
||||||
export default class Renderer {
|
export default class Renderer {
|
||||||
constructor ({
|
constructor ({
|
||||||
template,
|
template,
|
||||||
path,
|
context,
|
||||||
config,
|
config,
|
||||||
cache
|
cache
|
||||||
}) {
|
}) {
|
||||||
this.html = template
|
this.html = template
|
||||||
this.path = cwd(path || './')
|
this.context = cwd(context || './')
|
||||||
this.config = config = Object.assign({}, config, {
|
this.config = config = Object.assign({}, config, {
|
||||||
routerMode: 'history'
|
routerMode: 'history'
|
||||||
})
|
})
|
||||||
|
|
@ -54,7 +54,7 @@ export default class Renderer {
|
||||||
|
|
||||||
return isAbsolutePath(file)
|
return isAbsolutePath(file)
|
||||||
? file
|
? file
|
||||||
: cwd(this.path, `./${file}`)
|
: cwd(this.context, `./${file}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderToString (url) {
|
async renderToString (url) {
|
||||||
|
|
@ -114,6 +114,12 @@ export default class Renderer {
|
||||||
|
|
||||||
async _loadFile (filePath) {
|
async _loadFile (filePath) {
|
||||||
try {
|
try {
|
||||||
|
this.lock = this.lock || 0
|
||||||
|
if (++this.lock > 10) {
|
||||||
|
this.lock = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (isAbsolutePath(filePath)) {
|
if (isAbsolutePath(filePath)) {
|
||||||
const res = await fetch(filePath)
|
const res = await fetch(filePath)
|
||||||
return await res.text()
|
return await res.text()
|
||||||
|
|
@ -124,7 +130,7 @@ export default class Renderer {
|
||||||
const fileName = basename(filePath)
|
const fileName = basename(filePath)
|
||||||
const parentPath = cwd(filePath, '../..')
|
const parentPath = cwd(filePath, '../..')
|
||||||
|
|
||||||
if (this.path.length < parentPath.length) {
|
if (this.context.length < parentPath.length) {
|
||||||
throw Error(`Not found file ${fileName}`)
|
throw Error(`Not found file ${fileName}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue