Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit 404.html on build (#729) #740

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: share notFoundPageData
brc-dd committed Jun 7, 2022
commit c4e8df5cc7fd373b50d2ca204b7966fef74f435a
11 changes: 1 addition & 10 deletions src/client/app/router.ts
Original file line number Diff line number Diff line change
@@ -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<Router> = 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,
11 changes: 2 additions & 9 deletions src/node/build/render.ts
Original file line number Diff line number Diff line change
@@ -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
}

9 changes: 9 additions & 0 deletions src/shared/shared.ts
Original file line number Diff line number Diff line change
@@ -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
}