From c4e8df5cc7fd373b50d2ca204b7966fef74f435a Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 7 Jun 2022 20:26:12 +0530 Subject: [PATCH] refactor: share notFoundPageData --- src/client/app/router.ts | 11 +---------- src/node/build/render.ts | 11 ++--------- src/shared/shared.ts | 9 +++++++++ 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 4a6a277e..d978c92b 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -1,6 +1,6 @@ import { reactive, inject, markRaw, nextTick, readonly } from 'vue' import type { Component, InjectionKey } from 'vue' -import { PageData } from '../shared' +import { notFoundPageData, PageData } from '../shared' import { inBrowser, withBase } from './utils' import { siteDataRef } from './data' @@ -21,15 +21,6 @@ export const RouterSymbol: InjectionKey = Symbol() // matter and is only passed to support same-host hrefs. const fakeHost = `http://a.com` -const notFoundPageData: PageData = { - relativePath: '', - title: '404', - description: 'Not Found', - headers: [], - frontmatter: {}, - lastUpdated: 0 -} - const getDefaultRoute = (): Route => ({ path: '/', component: null, diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 84de2e02..ba6cd4d2 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -5,7 +5,7 @@ import { pathToFileURL } from 'url' import escape from 'escape-html' import { normalizePath, transformWithEsbuild } from 'vite' import { RollupOutput, OutputChunk, OutputAsset } from 'rollup' -import { HeadConfig, createTitle, PageData } from '../shared' +import { HeadConfig, createTitle, PageData, notFoundPageData } from '../shared' import { slash } from '../utils/slash' import { SiteConfig, resolveSiteDataByRoute } from '../config' @@ -64,14 +64,7 @@ export async function renderPage( } catch (e) { if (page === '404.md') { hasCustom404 = false - pageData = { - relativePath: '', - title: '404', - description: 'Not Found', - headers: [], - frontmatter: {}, - lastUpdated: 0 - } + pageData = notFoundPageData } else throw e } diff --git a/src/shared/shared.ts b/src/shared/shared.ts index f296f026..d5cda2cb 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -126,3 +126,12 @@ function cleanRoute(siteData: SiteData, route: string): string { return route.slice(baseWithoutSuffix.length) } + +export const notFoundPageData: PageData = { + relativePath: '', + title: '404', + description: 'Not Found', + headers: [], + frontmatter: {}, + lastUpdated: 0 +}