Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3fc596

Browse filesBrowse files
committed
fix(fetch): load sidebar and navbar for parent path, fixed #100
1 parent 07a2a91 commit f3fc596
Copy full SHA for f3fc596

2 files changed

+20-14Lines changed: 20 additions & 14 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/core/fetch/index.js‎

Copy file name to clipboardExpand all lines: src/core/fetch/index.js
+14-12Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { get } from './ajax'
22
import { callHook } from '../init/lifecycle'
3-
import { getRoot } from '../route/util'
3+
import { getParentPath } from '../route/util'
44
import { noop } from '../util/core'
55

6+
function loadNested (path, file, next, vm, first) {
7+
path = first ? path : path.replace(/\/$/, '')
8+
path = getParentPath(path)
9+
10+
if (!path) return
11+
12+
get(vm.$getFile(path + file))
13+
.then(next, _ => loadNested(path, file, next, vm))
14+
}
15+
616
export function fetchMixin (proto) {
717
let last
818
proto._fetch = function (cb = noop) {
919
const { path } = this.route
1020
const { loadNavbar, loadSidebar } = this.config
11-
const root = getRoot(path)
1221

1322
// Abort last request
1423
last && last.abort && last.abort()
@@ -26,25 +35,18 @@ export function fetchMixin (proto) {
2635
const fn = result => { this._renderSidebar(result); cb() }
2736

2837
// Load sidebar
29-
get(this.$getFile(root + loadSidebar))
30-
// fallback root navbar when fail
31-
.then(fn, _ => get(loadSidebar).then(fn))
38+
loadNested(path, loadSidebar, fn, this, true)
3239
},
3340
_ => this._renderMain(null))
3441

3542
// Load nav
3643
loadNavbar &&
37-
get(this.$getFile(root + loadNavbar))
38-
.then(
39-
text => this._renderNav(text),
40-
// fallback root navbar when fail
41-
_ => get(loadNavbar).then(text => this._renderNav(text))
42-
)
44+
loadNested(path, loadNavbar, text => this._renderNav(text), this, true)
4345
}
4446

4547
proto._fetchCover = function () {
4648
const { coverpage } = this.config
47-
const root = getRoot(this.route.path)
49+
const root = getParentPath(this.route.path)
4850
const path = this.$getFile(root + coverpage)
4951

5052
if (this.route.path !== '/' || !coverpage) {
Collapse file

‎src/core/route/util.js‎

Copy file name to clipboardExpand all lines: src/core/route/util.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ export const isAbsolutePath = cached(path => {
4545
return /(:|(\/{2}))/.test(path)
4646
})
4747

48-
export const getRoot = cached(path => {
49-
return /\/$/g.test(path) ? path : path.match(/(\S*\/)[^\/]+$/)[1]
48+
export const getParentPath = cached(path => {
49+
return /\/$/g.test(path)
50+
? path
51+
: (path = path.match(/(\S*\/)[^\/]+$/))
52+
? path[1]
53+
: ''
5054
})
5155

5256
export const cleanPath = cached(path => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.