From 7c3cdcf95e1b36d96e6dfa87d27c528be2339060 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Tue, 20 Jun 2023 15:34:23 +0330 Subject: [PATCH] fix(docusaurus-og): skip blog archive page if the html file does not exist --- .../docusaurus-og/src/server/blog.plugin.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/docusaurus-og/src/server/blog.plugin.ts b/packages/docusaurus-og/src/server/blog.plugin.ts index eda5e9a..9206bb9 100644 --- a/packages/docusaurus-og/src/server/blog.plugin.ts +++ b/packages/docusaurus-og/src/server/blog.plugin.ts @@ -62,6 +62,7 @@ export class BlogPlugin { if (content.blogTagsListPath) { const filePath = this.getHtmlPath(content.blogTagsListPath) + fs.existsSync(filePath) && this.pages.push({ pageType: 'tags', @@ -74,12 +75,18 @@ export class BlogPlugin { } if (options.archiveBasePath) { - this.pages.push({ - plugin: options, - pageType: 'archive', - data: { permalink: options.archiveBasePath }, - permalink: options.archiveBasePath, - }) + const filePath = this.getHtmlPath( + options.archiveBasePath, + options.routeBasePath, + ) + + fs.existsSync(filePath) && + this.pages.push({ + plugin: options, + pageType: 'archive', + data: { permalink: options.archiveBasePath }, + permalink: options.archiveBasePath, + }) } { @@ -120,6 +127,10 @@ export class BlogPlugin { } } - getHtmlPath = (permalink: string) => - path.join(this.context.outDir, permalink, 'index.html') + getHtmlPath = (permalink: string, baseUrl?: string) => + path.join( + this.context.outDir, + !baseUrl ? permalink : path.join('/', baseUrl, permalink), + 'index.html', + ) }