Correctly strip lang from path

Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
Joshua Castle
2024-03-24 19:43:45 -07:00
parent cc5c471b37
commit 7012c1ae55
9 changed files with 35 additions and 11 deletions
+1
View File
@@ -16,4 +16,5 @@ export declare class BlogPlugin {
loadInstance: (plugin: LoadedPlugin) => Promise<void>;
generate: () => Promise<void>;
getHtmlPath: (permalink: string, baseUrl?: string) => string;
stripLangFromPath: (path: string) => string;
}
+5 -1
View File
@@ -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;
+1
View File
@@ -19,4 +19,5 @@ export declare class DocsPlugin {
loadVersion: (options: DocsPluginOptions, version: LoadedVersion) => Promise<void>;
generate: () => Promise<void>;
getHtmlPath: (doc: Partial<DocsPageData>) => string | undefined;
stripLangFromPath: (path: string) => string;
}
+6 -4
View File
@@ -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;
+1
View File
@@ -16,4 +16,5 @@ export declare class PagesPlugin {
loadInstance: (plugin: LoadedPlugin) => Promise<void>;
generate: () => Promise<void>;
getHtmlPath: (permalink: string) => string;
stripLangFromPath: (path: string) => string;
}
+5 -1
View File
@@ -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;
+5 -1
View File
@@ -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
}
}
+6 -3
View File
@@ -99,7 +99,10 @@ export class DocsPlugin {
}
getHtmlPath = (doc: Partial<DocsPageData>) =>
// 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
}
}
+5 -1
View File
@@ -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
}
}