mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
refactor(ssr): path => context
This commit is contained in:
parent
891475e132
commit
d4f6072d10
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 = {
|
||||
alias: {
|
||||
'/de-de/changelog': '/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!'
|
||||
config: {
|
||||
alias: {
|
||||
'/de-de/changelog': '/changelog',
|
||||
'/zh-cn/changelog': '/changelog',
|
||||
'/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
|
||||
},
|
||||
paths: 'auto',
|
||||
placeholder: {
|
||||
'/de-de/': 'Suche',
|
||||
'/zh-cn/': '搜索',
|
||||
'/': 'Search'
|
||||
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',
|
||||
placeholder: {
|
||||
'/de-de/': 'Suche',
|
||||
'/zh-cn/': '搜索',
|
||||
'/': 'Search'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
context: './docs',
|
||||
template: './ssr.html'
|
||||
}
|
||||
|
||||
10
package.json
10
package.json
@ -20,15 +20,13 @@
|
||||
"themes"
|
||||
],
|
||||
"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": "node app & nodemon -w src -e js,css --exec 'npm run dev:build'",
|
||||
"build:ssr": "node build/build-ssr",
|
||||
"test": "eslint {src,packages} --fix"
|
||||
},
|
||||
"docsify": {
|
||||
"path": "./",
|
||||
"template": "./ssr.html"
|
||||
"test": "eslint {src,packages} --fix",
|
||||
"pub:next": "RELEASE_TAG=next sh build/release",
|
||||
"pub": "sh build/release"
|
||||
},
|
||||
"dependencies": {
|
||||
"marked": "^0.3.6",
|
||||
|
||||
@ -11,17 +11,15 @@ yarn add docsify-server-render
|
||||
```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'),
|
||||
template: readFileSync('./docs/index.template.html', 'utf-8').,
|
||||
context: './docs',
|
||||
config: {
|
||||
name: 'docsify',
|
||||
repo: 'qingwei-li/docsify'
|
||||
}
|
||||
//,cache: () => {}
|
||||
})
|
||||
|
||||
renderer.renderToString({ url })
|
||||
|
||||
@ -28,12 +28,12 @@ function mainTpl (config) {
|
||||
export default class Renderer {
|
||||
constructor ({
|
||||
template,
|
||||
path,
|
||||
context,
|
||||
config,
|
||||
cache
|
||||
}) {
|
||||
this.html = template
|
||||
this.path = cwd(path || './')
|
||||
this.context = cwd(context || './')
|
||||
this.config = config = Object.assign({}, config, {
|
||||
routerMode: 'history'
|
||||
})
|
||||
@ -54,7 +54,7 @@ export default class Renderer {
|
||||
|
||||
return isAbsolutePath(file)
|
||||
? file
|
||||
: cwd(this.path, `./${file}`)
|
||||
: cwd(this.context, `./${file}`)
|
||||
}
|
||||
|
||||
async renderToString (url) {
|
||||
@ -114,6 +114,12 @@ export default class Renderer {
|
||||
|
||||
async _loadFile (filePath) {
|
||||
try {
|
||||
this.lock = this.lock || 0
|
||||
if (++this.lock > 10) {
|
||||
this.lock = 0
|
||||
return
|
||||
}
|
||||
|
||||
if (isAbsolutePath(filePath)) {
|
||||
const res = await fetch(filePath)
|
||||
return await res.text()
|
||||
@ -124,7 +130,7 @@ export default class Renderer {
|
||||
const fileName = basename(filePath)
|
||||
const parentPath = cwd(filePath, '../..')
|
||||
|
||||
if (this.path.length < parentPath.length) {
|
||||
if (this.context.length < parentPath.length) {
|
||||
throw Error(`Not found file ${fileName}`)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user