Skip to content

Commit 4f14752

Browse files
committed
feat: add fallback default language support
1 parent 422a745 commit 4f14752

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

docs/configuration.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ window.$docsify = {
240240
};
241241
```
242242

243+
## fallbackDefaultLanguage
244+
245+
- Type: `String`
246+
- Default: `''`
247+
248+
When a page is requested and it doesn't exist for the given locale, Docsify will fallback to the language specified by this option.
249+
250+
For example, in the scenario described above, if `/de/overview` does not exist and `fallbackDefaultLanguage` is configured as `zh-cn`, Docsify will fetch `/zh-cn/overview` instead of `/overview`.
251+
252+
```js
253+
window.$docsify = {
254+
fallbackLanguages: ['fr', 'de'],
255+
fallbackDefaultLanguage: 'zh-cn', // default: ''
256+
};
257+
```
258+
243259
## formatUpdated
244260

245261
- Type: `String|Function`
@@ -262,7 +278,7 @@ window.$docsify = {
262278
## hideSidebar
263279

264280
- Type : `Boolean`
265-
- Default: `true`
281+
- Default: `false`
266282

267283
This option will completely hide your sidebar and won't render any content on the side.
268284

src/core/config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const currentScript = document.currentScript;
77
export default function (vm) {
88
const config = Object.assign(
99
{
10+
alias: {},
1011
auto2top: false,
1112
autoHeader: false,
1213
basePath: '',
@@ -18,11 +19,16 @@ export default function (vm) {
1819
ext: '.md',
1920
externalLinkRel: 'noopener',
2021
externalLinkTarget: '_blank',
22+
fallbackLanguages: null,
23+
fallbackDefaultLanguage: '',
2124
formatUpdated: '',
22-
ga: '',
25+
hideSidebar: false,
2326
homepage: 'README.md',
27+
keyBindings: {},
2428
loadNavbar: null,
2529
loadSidebar: null,
30+
logo: false,
31+
markdown: null,
2632
maxLevel: 6,
2733
mergeNavbar: false,
2834
name: '',
@@ -31,11 +37,14 @@ export default function (vm) {
3137
noCompileLinks: [],
3238
noEmoji: false,
3339
notFoundPage: false,
40+
onlyCover: false,
3441
plugins: [],
3542
relativePath: false,
3643
repo: '',
37-
routes: {},
44+
requestHeaders: {},
3845
routerMode: 'hash',
46+
routes: {},
47+
skipLink: 'Skip to main content',
3948
subMaxLevel: 0,
4049
// themeColor: '',
4150
topMargin: 0,

src/core/fetch/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ export function Fetch(Base) {
204204
}
205205

206206
_fetchFallbackPage(path, qs, cb = noop) {
207-
const { requestHeaders, fallbackLanguages, loadSidebar } = this.config;
207+
const {
208+
requestHeaders,
209+
fallbackLanguages,
210+
fallbackDefaultLanguage,
211+
loadSidebar,
212+
} = this.config;
208213

209214
if (!fallbackLanguages) {
210215
return false;
@@ -217,7 +222,7 @@ export function Fetch(Base) {
217222
}
218223

219224
const newPath = this.router.getFile(
220-
path.replace(new RegExp(`^/${local}`), ''),
225+
path.replace(new RegExp(`^/${local}`), fallbackDefaultLanguage),
221226
);
222227
const req = this.#request(newPath + qs, requestHeaders);
223228

0 commit comments

Comments
 (0)