Skip to content

Commit

Permalink
revert: fix: handle cleanUrls with subfolders when using a trailing s…
Browse files Browse the repository at this point in the history
…lash
  • Loading branch information
rigor789 authored and brc-dd committed Dec 21, 2022
1 parent 9a7e5ce commit 40db044
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
description: 'Vite & Vue powered static site generator.',

lastUpdated: true,
cleanUrls: 'with-subfolders',
cleanUrls: 'without-subfolders',

head: [['meta', { name: 'theme-color', content: '#3c8772' }]],

Expand Down
12 changes: 1 addition & 11 deletions src/node/build/buildMPAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@ export async function buildMPAClient(
): Promise<RollupOutput> {
const files = Object.keys(js)
const themeFiles = files.filter((f) => !f.endsWith('.md'))
const pages = files
.filter((f) => f.endsWith('.md'))
.map((page) => {
if (
config.cleanUrls === 'with-subfolders' &&
!page.includes('index.md')
) {
return page.replace('.md', '_index.md')
}
return page
})
const pages = files.filter((f) => f.endsWith('.md'))

return build({
root: config.srcDir,
Expand Down
9 changes: 1 addition & 8 deletions src/node/build/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ export async function bundle(
config.pages.forEach((file) => {
// page filename conversion
// foo/bar.md -> foo_bar.md
// when using cleanUrls with-subfolders
// foo/bar.md -> foo_bar_index.md
let target = slash(file).replace(/\//g, '_')
if (config.cleanUrls === 'with-subfolders' && !file.includes('index.md')) {
target = target.replace('.md', '_index.md')
}

input[target] = path.resolve(config.srcDir, file)
input[slash(file).replace(/\//g, '_')] = path.resolve(config.srcDir, file)
})

// resolve options to pass to vite
Expand Down
10 changes: 1 addition & 9 deletions src/node/build/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ export async function renderPage(
// render page
const content = await render(routePath)

let pageName = sanitizeFileName(page.replace(/\//g, '_'))

if (
config.cleanUrls === 'with-subfolders' &&
!pageName.includes('index.md')
) {
pageName = pageName.replace('.md', '_index.md')
}

const pageName = sanitizeFileName(page.replace(/\//g, '_'))
// server build doesn't need hash
const pageServerJsFileName = pageName + '.js'
// for any initial page load, we only need the lean version of the page js
Expand Down

0 comments on commit 40db044

Please sign in to comment.