Compare commits

..
3 Commits
Author SHA1 Message Date
qingwei.li 43fc8b8ab1 [release] 4.0.2 next 2017-05-30 10:14:42 +08:00
qingwei.li ccec23df7f [build] 4.0.2 next 2017-05-30 10:14:41 +08:00
qingwei.li fc1cd3f11d fix: basePath for history mode 2017-05-30 10:11:48 +08:00
10 changed files with 48 additions and 38 deletions
+19 -16
View File
@@ -79,7 +79,8 @@ var config = merge({
ga: '',
mergeNavbar: false,
formatUpdated: '',
externalLinkTarget: '_blank'
externalLinkTarget: '_blank',
routerModel: 'hash'
}, window.$docsify);
var script = document.currentScript ||
@@ -3311,6 +3312,8 @@ History.prototype.getBasePath = function getBasePath () {
};
History.prototype.getFile = function getFile (path) {
path = path || this.getCurrentPath();
var ref = this;
var config = ref.config;
var base = this.getBasePath();
@@ -3411,7 +3414,11 @@ var HashHistory = (function (History$$1) {
path = path.slice(hashIndex + 1);
}
return { path: path, query: parseQuery(query) }
return {
path: path,
file: this.getFile(path),
query: parseQuery(query)
}
};
HashHistory.prototype.toURL = function toURL (path, params, currentRoute) {
@@ -3441,7 +3448,7 @@ var HTML5History = (function (History$$1) {
HTML5History.prototype.constructor = HTML5History;
HTML5History.prototype.getCurrentPath = function getCurrentPath () {
var base = this.config.basePath;
var base = this.getBasePath();
var path = window.location.pathname;
if (base && path.indexOf(base) === 0) {
@@ -3470,15 +3477,6 @@ var HTML5History = (function (History$$1) {
on('popstate', cb);
};
HTML5History.prototype.normalize = function normalize () {
var path = this.getCurrentPath();
path = path.replace('#', '?id=');
window.history.pushState({ key: path }, '', path);
return path
};
/**
* Parse the url
* @param {string} [path=location.href]
@@ -3495,12 +3493,18 @@ var HTML5History = (function (History$$1) {
path = path.slice(0, queryIndex);
}
var baseIndex = path.indexOf(location.origin);
var base = getPath(location.origin, this.getBasePath());
var baseIndex = path.indexOf(base);
if (baseIndex > -1) {
path = path.slice(baseIndex + location.origin.length);
path = path.slice(baseIndex + base.length - 1);
}
return { path: path, query: parseQuery(query) }
return {
path: path,
file: this.getFile(path),
query: parseQuery(query)
}
};
HTML5History.prototype.toURL = function toURL (path, params, currentRoute) {
@@ -3630,7 +3634,6 @@ function fetchMixin (proto) {
var root = getParentPath(this.route.path);
var path = this.router.getFile(root + coverpage);
console.log(this.route.path, root, path);
if (this.route.path !== '/' || !coverpage) {
this._renderCover();
return
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docsify",
"version": "4.0.1",
"version": "4.0.2",
"description": "A magical documentation generator.",
"author": {
"name": "qingwei-li",
@@ -1,6 +1,6 @@
{
"name": "docsify-server-renderer",
"version": "4.0.1",
"version": "4.0.2",
"description": "docsify server renderer",
"author": {
"name": "qingwei-li",
+2 -1
View File
@@ -20,7 +20,8 @@ const config = merge({
ga: '',
mergeNavbar: false,
formatUpdated: '',
externalLinkTarget: '_blank'
externalLinkTarget: '_blank',
routerModel: 'hash'
}, window.$docsify)
const script = document.currentScript ||
-1
View File
@@ -50,7 +50,6 @@ export function fetchMixin (proto) {
const root = getParentPath(this.route.path)
const path = this.router.getFile(root + coverpage)
console.log(this.route.path, root, path)
if (this.route.path !== '/' || !coverpage) {
this._renderCover()
return
+5 -1
View File
@@ -17,7 +17,11 @@ export class AbstractHistory extends History {
path = path.slice(0, queryIndex)
}
return { path, query: parseQuery(query) }
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}
toURL (path, params, currentRoute) {
+2
View File
@@ -23,6 +23,8 @@ export class History {
}
getFile (path) {
path = path || this.getCurrentPath()
const { config } = this
const base = this.getBasePath()
+5 -1
View File
@@ -69,7 +69,11 @@ export class HashHistory extends History {
path = path.slice(hashIndex + 1)
}
return { path, query: parseQuery(query) }
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}
toURL (path, params, currentRoute) {
+11 -14
View File
@@ -1,7 +1,7 @@
import { History } from './base'
import { merge, noop } from '../../util/core'
import { on } from '../../util/dom'
import { parseQuery, stringifyQuery, cleanPath } from '../util'
import { parseQuery, stringifyQuery, getPath, cleanPath } from '../util'
export class HTML5History extends History {
constructor (config) {
@@ -10,7 +10,7 @@ export class HTML5History extends History {
}
getCurrentPath () {
const base = this.config.basePath
const base = this.getBasePath()
let path = window.location.pathname
if (base && path.indexOf(base) === 0) {
@@ -37,15 +37,6 @@ export class HTML5History extends History {
on('popstate', cb)
}
normalize () {
let path = this.getCurrentPath()
path = path.replace('#', '?id=')
window.history.pushState({ key: path }, '', path)
return path
}
/**
* Parse the url
* @param {string} [path=location.href]
@@ -60,12 +51,18 @@ export class HTML5History extends History {
path = path.slice(0, queryIndex)
}
const baseIndex = path.indexOf(location.origin)
const base = getPath(location.origin, this.getBasePath())
const baseIndex = path.indexOf(base)
if (baseIndex > -1) {
path = path.slice(baseIndex + location.origin.length)
path = path.slice(baseIndex + base.length - 1)
}
return { path, query: parseQuery(query) }
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}
toURL (path, params, currentRoute) {