diff --git a/lib/server/blog.plugin.d.ts b/lib/server/blog.plugin.d.ts index 070e18d..8286660 100644 --- a/lib/server/blog.plugin.d.ts +++ b/lib/server/blog.plugin.d.ts @@ -16,4 +16,5 @@ export declare class BlogPlugin { loadInstance: (plugin: LoadedPlugin) => Promise; generate: () => Promise; getHtmlPath: (permalink: string, baseUrl?: string) => string; + stripLangFromPath: (path: string) => string; } diff --git a/lib/server/blog.plugin.js b/lib/server/blog.plugin.js index 9d723b7..c8230b7 100644 --- a/lib/server/blog.plugin.js +++ b/lib/server/blog.plugin.js @@ -114,6 +114,10 @@ class BlogPlugin { bar.stop(); logger_1.default.success('Generated og images for blog pages'); }; - getHtmlPath = (permalink, baseUrl) => path.join(this.context.outDir, permalink, 'index.html'); + getHtmlPath = (permalink, baseUrl) => path.join(this.stripLangFromPath(this.context.outDir), permalink, 'index.html'); + stripLangFromPath = (path) => { + const lang = this.context.i18n.locales.find((locale) => path.endsWith(`/${locale}`)); + return lang ? path.slice(0, -lang.length - 1) : path; + }; } exports.BlogPlugin = BlogPlugin; diff --git a/lib/server/docs.plugin.d.ts b/lib/server/docs.plugin.d.ts index 5042938..1fa5e67 100644 --- a/lib/server/docs.plugin.d.ts +++ b/lib/server/docs.plugin.d.ts @@ -19,4 +19,5 @@ export declare class DocsPlugin { loadVersion: (options: DocsPluginOptions, version: LoadedVersion) => Promise; generate: () => Promise; getHtmlPath: (doc: Partial) => string | undefined; + stripLangFromPath: (path: string) => string; } diff --git a/lib/server/docs.plugin.js b/lib/server/docs.plugin.js index bf10999..5cbd6b4 100644 --- a/lib/server/docs.plugin.js +++ b/lib/server/docs.plugin.js @@ -71,9 +71,11 @@ class DocsPlugin { bar.stop(); logger_1.default.success('Generated og images for docs pages'); }; - getHtmlPath = (doc) => - // slug is used here instead of permalink because permalink already contains version and locale paths of websiteOutDir - doc.metadata?.slug && - path.join(this.context.outDir, doc.metadata.slug, 'index.html'); + getHtmlPath = (doc) => doc.metadata?.permalink && + path.join(this.stripLangFromPath(this.context.outDir), doc.metadata.permalink, 'index.html'); + stripLangFromPath = (path) => { + const lang = this.context.i18n.locales.find((locale) => path.endsWith(`/${locale}`)); + return lang ? path.slice(0, -lang.length - 1) : path; + }; } exports.DocsPlugin = DocsPlugin; diff --git a/lib/server/pages.plugin.d.ts b/lib/server/pages.plugin.d.ts index 0e82d8d..ce0fd1b 100644 --- a/lib/server/pages.plugin.d.ts +++ b/lib/server/pages.plugin.d.ts @@ -16,4 +16,5 @@ export declare class PagesPlugin { loadInstance: (plugin: LoadedPlugin) => Promise; generate: () => Promise; getHtmlPath: (permalink: string) => string; + stripLangFromPath: (path: string) => string; } diff --git a/lib/server/pages.plugin.js b/lib/server/pages.plugin.js index ac429a8..b91d43c 100644 --- a/lib/server/pages.plugin.js +++ b/lib/server/pages.plugin.js @@ -81,6 +81,10 @@ class PagesPlugin { bar.stop(); logger_1.default.success('Generated og images for pages'); }; - getHtmlPath = (permalink) => path.join(this.context.outDir, permalink, 'index.html'); + getHtmlPath = (permalink) => path.join(this.stripLangFromPath(this.context.outDir), permalink, 'index.html'); + stripLangFromPath = (path) => { + const lang = this.context.i18n.locales.find((locale) => path.endsWith(`/${locale}`)); + return lang ? path.slice(0, -lang.length - 1) : path; + }; } exports.PagesPlugin = PagesPlugin; diff --git a/src/server/blog.plugin.ts b/src/server/blog.plugin.ts index 9e59c5e..ae7e9a9 100644 --- a/src/server/blog.plugin.ts +++ b/src/server/blog.plugin.ts @@ -148,5 +148,9 @@ export class BlogPlugin { } getHtmlPath = (permalink: string, baseUrl?: string) => - path.join(this.context.outDir, permalink, 'index.html') + path.join(this.stripLangFromPath(this.context.outDir), permalink, 'index.html') + stripLangFromPath = (path: string) => { + const lang = this.context.i18n.locales.find((locale) => path.endsWith(`/${locale}`)) + return lang ? path.slice(0, -lang.length - 1) : path + } } diff --git a/src/server/docs.plugin.ts b/src/server/docs.plugin.ts index ffa90b0..4b855e9 100644 --- a/src/server/docs.plugin.ts +++ b/src/server/docs.plugin.ts @@ -99,7 +99,10 @@ export class DocsPlugin { } getHtmlPath = (doc: Partial) => - // slug is used here instead of permalink because permalink already contains version and locale paths of websiteOutDir - doc.metadata?.slug && - path.join(this.context.outDir, doc.metadata.slug, 'index.html') + doc.metadata?.permalink && + path.join(this.stripLangFromPath(this.context.outDir), doc.metadata.permalink, 'index.html') + stripLangFromPath = (path: string) => { + const lang = this.context.i18n.locales.find((locale) => path.endsWith(`/${locale}`)) + return lang ? path.slice(0, -lang.length - 1) : path + } } diff --git a/src/server/pages.plugin.ts b/src/server/pages.plugin.ts index 57a35ec..be2b4ce 100644 --- a/src/server/pages.plugin.ts +++ b/src/server/pages.plugin.ts @@ -109,5 +109,9 @@ export class PagesPlugin { } getHtmlPath = (permalink: string) => - path.join(this.context.outDir, permalink, 'index.html') + path.join(this.stripLangFromPath(this.context.outDir), permalink, 'index.html') + stripLangFromPath = (path: string) => { + const lang = this.context.i18n.locales.find((locale) => path.endsWith(`/${locale}`)) + return lang ? path.slice(0, -lang.length - 1) : path + } }