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

fix: handle cleanUrls with subfolders when using a trailing slash #1575

Merged
Merged
Prev Previous commit
Next Next commit
revert: fix: handle cleanUrls with subfolders when using a trailing s…
…lash
  • Loading branch information
rigor789 authored and brc-dd committed Dec 21, 2022
commit 40db0441868103acd98cc48db2efa3e4f47f15ed
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