simplify stuff

pull/1575/head
Divyansh Singh 4 years ago
parent affdecaf46
commit ff6bf3522e

@ -22,24 +22,7 @@ export function withBase(path: string) {
export function pathToFile(path: string): string { export function pathToFile(path: string): string {
let pagePath = path.replace(/\.html$/, '') let pagePath = path.replace(/\.html$/, '')
pagePath = decodeURIComponent(pagePath) pagePath = decodeURIComponent(pagePath)
pagePath = pagePath.replace(/\/$/, '/index') // /foo/ -> /foo/index
if (pagePath.endsWith('/')) {
if (import.meta.env.DEV) {
// in dev, we are importing the md files directly, and if there's a trailing slash
// it's likely an index.md file
pagePath += 'index'
} else {
// remove trailing slashes from pagePath
pagePath = pagePath.slice(0, -1)
}
}
// if we removed the trailing slash and have an empty page path
// we are trying to render the index/home page...
if (pagePath.length === 0) {
pagePath = '/index'
}
if (import.meta.env.DEV) { if (import.meta.env.DEV) {
// always force re-fetch content in dev // always force re-fetch content in dev
pagePath += `.md?t=${Date.now()}` pagePath += `.md?t=${Date.now()}`
@ -56,13 +39,10 @@ export function pathToFile(path: string): string {
// client production build needs to account for page hash, which is // client production build needs to account for page hash, which is
// injected directly in the page's html // injected directly in the page's html
let pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] let pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()]
if (!pageHash && pagePath.endsWith('_index.md')) {
if (!pageHash) { pagePath = pagePath.slice(0, -9) + '.md'
// try looking for an index.md hash
pagePath = pagePath.replace('.md', '_index.md')
pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()]
} }
pagePath = `${base}assets/${pagePath}.${pageHash}.js` pagePath = `${base}assets/${pagePath}.${pageHash}.js`
} else { } else {
// ssr build uses much simpler name mapping // ssr build uses much simpler name mapping

Loading…
Cancel
Save