Feat/1.2 (#33)

* Add homepage option, fixed #30

* Add custom basePath support, resolve #31
This commit is contained in:
cinwell.li 2016-12-20 21:18:52 +08:00 committed by GitHub
commit f9d75ab931
5 changed files with 62 additions and 7 deletions

View file

@ -11,6 +11,8 @@ const OPTIONS = {
loadSidebar: null,
loadNavbar: null,
router: false,
homepage: 'README.md',
basePath: '',
auto2top: false
}
const script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop()
@ -33,8 +35,9 @@ let cacheRoute = null
let cacheXhr = null
const mainRender = function (cb) {
const route = getRoute()
const route = OPTIONS.basePath + getRoute()
if (cacheRoute === route) return cb()
let wait
let basePath = cacheRoute = route
@ -44,13 +47,18 @@ const mainRender = function (cb) {
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()
// Render markdown file
cacheXhr = load(
(!route || /\/$/.test(route)) ? `${route}README.md` : `${route}.md`,
'GET',
render.renderLoading)
cacheXhr = load(page, 'GET', render.renderLoading)
cacheXhr.then(result => {
render.renderArticle(result)
if (OPTIONS.loadSidebar) {