Feat/1.2 (#33)
* Add homepage option, fixed #30 * Add custom basePath support, resolve #31
This commit is contained in:
parent
f93f9ceb09
commit
f9d75ab931
5 changed files with 62 additions and 7 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
## 1.2.0
|
||||||
|
### Features
|
||||||
|
- custom basePath
|
||||||
|
- custom homepage
|
||||||
|
|
||||||
## 1.1.7
|
## 1.1.7
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
- Optimize progress bar
|
- Optimize progress bar
|
||||||
|
|
|
||||||
|
|
@ -240,3 +240,24 @@ Scroll to the top on changing hash.
|
||||||
<script src="/lib/docsify.js" data-auto2top></script>
|
<script src="/lib/docsify.js" data-auto2top></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### homepage
|
||||||
|
|
||||||
|
`README.md` will be render as homepage for your website in docs folder, but sometimes we want to specify another file as a homepage, or even use the `README.md` in your repo. we can use:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="/lib/docsify.js" data-homepage="https://raw.githubusercontent.com/QingWei-Li/docsify/master/README.md"></script>
|
||||||
|
<!-- Or using `Welcome.md` as homepge -->
|
||||||
|
<script src="/lib/docsify.js" data-homepage="Welcome.md"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### basePath
|
||||||
|
|
||||||
|
If your HTML entry file and the markdown files are in different directories, we can use:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="/lib/docsify.js" data-base-path="/base/"></script>
|
||||||
|
|
||||||
|
<!-- Even if the docs is on another site 😄 -->
|
||||||
|
<script src="/lib/docsify.js" data-base-path="https://docsify.js.org/"></script>
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -237,3 +237,24 @@ Sidebar 开关按钮
|
||||||
<script src="/lib/docsify.js" data-auto2top></script>
|
<script src="/lib/docsify.js" data-auto2top></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### homepage
|
||||||
|
|
||||||
|
默认情况下网站会将根目录下 `README.md` 作为首页渲染,但是有些时候我们想指定其他文件,甚至想直接将 repo 下的 README 作为首页。你可以这样做:
|
||||||
|
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="/lib/docsify.js" data-homepage="https://raw.githubusercontent.com/QingWei-Li/docsify/master/README.md"></script>
|
||||||
|
<!-- 或者将 Welcome.md 作为首页 -->
|
||||||
|
<script src="/lib/docsify.js" data-homepage="Welcome.md"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### basePath
|
||||||
|
|
||||||
|
指定加载文档的路径,如果你的 HTML 入口文件和文档是放在不同地方,你可以设置:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="/lib/docsify.js" data-base-path="/base/"></script>
|
||||||
|
|
||||||
|
<!-- 甚至文档是在其他站点下 😄 -->
|
||||||
|
<script src="/lib/docsify.js" data-base-path="https://docsify.js.org/"></script>
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf lib themes && node build/build.js && mkdir lib/themes && mkdir themes && node build/build-css.js",
|
"build": "rm -rf lib themes && node build/build.js && mkdir lib/themes && mkdir themes && node build/build-css.js",
|
||||||
"dev": "node app.js & nodemon -w src --exec 'npm run build'",
|
"dev": "node app.js & nodemon -w src -e js,css --exec 'npm run build'",
|
||||||
"test": "eslint src test"
|
"test": "eslint src test"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
20
src/index.js
20
src/index.js
|
|
@ -11,6 +11,8 @@ const OPTIONS = {
|
||||||
loadSidebar: null,
|
loadSidebar: null,
|
||||||
loadNavbar: null,
|
loadNavbar: null,
|
||||||
router: false,
|
router: false,
|
||||||
|
homepage: 'README.md',
|
||||||
|
basePath: '',
|
||||||
auto2top: false
|
auto2top: false
|
||||||
}
|
}
|
||||||
const script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop()
|
const script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop()
|
||||||
|
|
@ -33,8 +35,9 @@ let cacheRoute = null
|
||||||
let cacheXhr = null
|
let cacheXhr = null
|
||||||
|
|
||||||
const mainRender = function (cb) {
|
const mainRender = function (cb) {
|
||||||
const route = getRoute()
|
const route = OPTIONS.basePath + getRoute()
|
||||||
if (cacheRoute === route) return cb()
|
if (cacheRoute === route) return cb()
|
||||||
|
|
||||||
let wait
|
let wait
|
||||||
let basePath = cacheRoute = route
|
let basePath = cacheRoute = route
|
||||||
|
|
||||||
|
|
@ -44,13 +47,18 @@ const mainRender = function (cb) {
|
||||||
basePath = basePath.match(/(\S*\/)[^\/]+$/)[1]
|
basePath = basePath.match(/(\S*\/)[^\/]+$/)[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let page
|
||||||
|
if (!route) {
|
||||||
|
page = OPTIONS.homepage || 'README.md'
|
||||||
|
} else if (/\/$/.test(route)) {
|
||||||
|
page = `${route}README.md`
|
||||||
|
} else {
|
||||||
|
page = `${route}.md`
|
||||||
|
}
|
||||||
|
|
||||||
cacheXhr && cacheXhr.abort && cacheXhr.abort()
|
cacheXhr && cacheXhr.abort && cacheXhr.abort()
|
||||||
// Render markdown file
|
// Render markdown file
|
||||||
cacheXhr = load(
|
cacheXhr = load(page, 'GET', render.renderLoading)
|
||||||
(!route || /\/$/.test(route)) ? `${route}README.md` : `${route}.md`,
|
|
||||||
'GET',
|
|
||||||
render.renderLoading)
|
|
||||||
|
|
||||||
cacheXhr.then(result => {
|
cacheXhr.then(result => {
|
||||||
render.renderArticle(result)
|
render.renderArticle(result)
|
||||||
if (OPTIONS.loadSidebar) {
|
if (OPTIONS.loadSidebar) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue