@@ -22,15 +22,39 @@ export function fetchMixin (proto) {
22
22
proto . _fetch = function ( cb = noop ) {
23
23
const { path, query } = this . route
24
24
const qs = stringifyQuery ( query , [ 'id' ] )
25
- const { loadNavbar, loadSidebar, requestHeaders } = this . config
26
-
25
+ const { loadNavbar, loadSidebar, requestHeaders, fallbackLanguages } = this . config
27
26
// Abort last request
28
27
last && last . abort && last . abort ( )
29
28
30
- last = get ( this . router . getFile ( path ) + qs , true , requestHeaders )
29
+ const file = this . router . getFile ( path )
30
+ last = get ( file + qs , true , requestHeaders )
31
31
32
32
// Current page is html
33
- this . isHTML = / \. h t m l $ / g. test ( path )
33
+ this . isHTML = / \. h t m l $ / g. test ( file )
34
+
35
+ const getFallBackPage = ( file ) => {
36
+ if ( ! fallbackLanguages ) {
37
+ return false
38
+ }
39
+
40
+ const local = file . split ( '/' ) [ 1 ]
41
+
42
+ if ( fallbackLanguages . indexOf ( local ) === - 1 ) {
43
+ return false
44
+ }
45
+
46
+ file = file . replace ( new RegExp ( `^/${ local } ` ) , '' )
47
+
48
+ return get ( file + qs , true , requestHeaders )
49
+ . then (
50
+ ( text , opt ) => {
51
+ this . _renderMain ( text , opt , loadSideAndNav )
52
+ } ,
53
+ _ => {
54
+ return this . _renderMain ( null , { } , loadSideAndNav )
55
+ }
56
+ )
57
+ }
34
58
35
59
const loadSideAndNav = ( ) => {
36
60
if ( ! loadSidebar ) return cb ( )
@@ -45,25 +69,26 @@ export function fetchMixin (proto) {
45
69
}
46
70
47
71
// Load main content
48
- last . then (
49
- ( text , opt ) => {
50
- this . _renderMain ( text , opt , loadSideAndNav )
51
- } ,
52
- _ => {
53
- this . _renderMain ( null , { } , loadSideAndNav )
54
- }
55
- )
72
+ last
73
+ . then (
74
+ ( text , opt ) => {
75
+ this . _renderMain ( text , opt , loadSideAndNav )
76
+ } ,
77
+ _ => {
78
+ return getFallBackPage ( file ) || this . _renderMain ( null , { } , loadSideAndNav )
79
+ }
80
+ )
56
81
57
82
// Load nav
58
83
loadNavbar &&
59
- loadNested (
60
- path ,
61
- qs ,
62
- loadNavbar ,
63
- text => this . _renderNav ( text ) ,
64
- this ,
65
- true
66
- )
84
+ loadNested (
85
+ path ,
86
+ qs ,
87
+ loadNavbar ,
88
+ text => this . _renderNav ( text ) ,
89
+ this ,
90
+ true
91
+ )
67
92
}
68
93
69
94
proto . _fetchCover = function ( ) {
0 commit comments