Skip to content

Commit

Permalink
[gem-book] Fixed self language detect without i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Jan 8, 2024
1 parent 8337376 commit 4b8626a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/gem-book/docs/zh/003-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ yarn add gem-book

## `<gbp-include>`

动态加载显示 MarkDown 片段:
动态加载显示 Markdown 片段:

<gbp-include src="./002-guide/007-extension.md" range="[!NOTE]->"></gbp-include>

Expand Down
2 changes: 1 addition & 1 deletion packages/gem-book/gem-book.cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"i18n": true,
"homeMode": true,
"sourceBranch": "docs",
"plugin": ["raw", "docsearch", "api", "sandpack", "code-group", "import"],
"plugin": ["raw", "docsearch", "api", "sandpack", "code-group", "import", "include", "var", "example"],
"template": "docs/template.html",
"ga": "G-PZYZ441YD3",
"debug": true,
Expand Down
4 changes: 3 additions & 1 deletion packages/gem-book/src/element/elements/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ function getRemoteURL(originSrc = '', dev = GemBookPluginElement.devMode) {
let src = originSrc.startsWith('/') ? originSrc : `/${originSrc}`;
if (originSrc.startsWith('.')) {
const absPath = new URL(originSrc, `${location.origin}${originLink}`).pathname;
const link = links?.find(({ originLink }) => originLink === absPath);
const link = links?.find(({ originLink, link, userFullPath }) =>
[originLink, link, userFullPath].some((path) => path === absPath),
);
if (link) return getURL(joinPath(lang, link.originLink), link.hash);
src = new URL(originSrc, `${location.origin}${joinPath(sourceDir, lang, originLink)}`).pathname;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/gem-book/src/element/helper/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export const fallbackLanguage = document.documentElement.lang;
export const selfI18n = new I18n<typeof resources.en>({
fallbackLanguage: fallbackLanguage in resources ? fallbackLanguage : 'en',
resources,
// 没有启动 i18n 时由 `html[lang]` 定义语言
currentLanguage: fallbackLanguage,
});

0 comments on commit 4b8626a

Please sign in to comment.