From c09895ef1c27e59bdc9c793bf97a760dbc7fda69 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Fri, 22 Nov 2024 07:40:29 +0800 Subject: [PATCH] fix(plugin-shikiji): in copy-code, unknown locales fallback not set (#348) --- plugins/plugin-shikiji/__test__/copyCodeButton.spec.ts | 2 +- .../src/node/copy-code-button/createCopyCodeButtonRender.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-shikiji/__test__/copyCodeButton.spec.ts b/plugins/plugin-shikiji/__test__/copyCodeButton.spec.ts index e3afd563..88003d3b 100644 --- a/plugins/plugin-shikiji/__test__/copyCodeButton.spec.ts +++ b/plugins/plugin-shikiji/__test__/copyCodeButton.spec.ts @@ -13,7 +13,7 @@ function createMarkdown(options: boolean | CopyCodeOptions = {}, lang = 'en-US') env: { isDebug: false }, siteData: { lang, - locales: { '/': { lang }, '/zh/': { lang: 'zh-CN' }, '/en/': { lang: 'en-US' } }, + locales: { '/': { lang }, '/zh/': { lang: 'zh-CN' }, '/en/': { lang: 'en-US' }, '/xxx/': { lang: 'unknown' } }, }, } as unknown as App copyCodeButtonPlugin(md, app, options) diff --git a/plugins/plugin-shikiji/src/node/copy-code-button/createCopyCodeButtonRender.ts b/plugins/plugin-shikiji/src/node/copy-code-button/createCopyCodeButtonRender.ts index a3925c67..f965ce15 100644 --- a/plugins/plugin-shikiji/src/node/copy-code-button/createCopyCodeButtonRender.ts +++ b/plugins/plugin-shikiji/src/node/copy-code-button/createCopyCodeButtonRender.ts @@ -32,7 +32,7 @@ export function createCopyCodeButtonRender(app: App, options?: boolean | CopyCod return (filePathRelative: string) => { const relativePath = ensureLeadingSlash(filePathRelative) const localePath = resolveLocalePath(locales, relativePath) - const { title, copied } = locales[localePath] + const { title, copied } = locales[localePath] || locales['/'] return `` }