refactor: share notFoundPageData

pull/740/head
Divyansh Singh 3 years ago
parent 9aed4d1ea9
commit c4e8df5cc7

@ -1,6 +1,6 @@
import { reactive, inject, markRaw, nextTick, readonly } from 'vue' import { reactive, inject, markRaw, nextTick, readonly } from 'vue'
import type { Component, InjectionKey } from 'vue' import type { Component, InjectionKey } from 'vue'
import { PageData } from '../shared' import { notFoundPageData, PageData } from '../shared'
import { inBrowser, withBase } from './utils' import { inBrowser, withBase } from './utils'
import { siteDataRef } from './data' import { siteDataRef } from './data'
@ -21,15 +21,6 @@ export const RouterSymbol: InjectionKey<Router> = Symbol()
// matter and is only passed to support same-host hrefs. // matter and is only passed to support same-host hrefs.
const fakeHost = `http://a.com` const fakeHost = `http://a.com`
const notFoundPageData: PageData = {
relativePath: '',
title: '404',
description: 'Not Found',
headers: [],
frontmatter: {},
lastUpdated: 0
}
const getDefaultRoute = (): Route => ({ const getDefaultRoute = (): Route => ({
path: '/', path: '/',
component: null, component: null,

@ -5,7 +5,7 @@ import { pathToFileURL } from 'url'
import escape from 'escape-html' import escape from 'escape-html'
import { normalizePath, transformWithEsbuild } from 'vite' import { normalizePath, transformWithEsbuild } from 'vite'
import { RollupOutput, OutputChunk, OutputAsset } from 'rollup' 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 { slash } from '../utils/slash'
import { SiteConfig, resolveSiteDataByRoute } from '../config' import { SiteConfig, resolveSiteDataByRoute } from '../config'
@ -64,14 +64,7 @@ export async function renderPage(
} catch (e) { } catch (e) {
if (page === '404.md') { if (page === '404.md') {
hasCustom404 = false hasCustom404 = false
pageData = { pageData = notFoundPageData
relativePath: '',
title: '404',
description: 'Not Found',
headers: [],
frontmatter: {},
lastUpdated: 0
}
} else throw e } else throw e
} }

@ -126,3 +126,12 @@ function cleanRoute(siteData: SiteData, route: string): string {
return route.slice(baseWithoutSuffix.length) return route.slice(baseWithoutSuffix.length)
} }
export const notFoundPageData: PageData = {
relativePath: '',
title: '404',
description: 'Not Found',
headers: [],
frontmatter: {},
lastUpdated: 0
}

Loading…
Cancel
Save