From 982d6bff2ac3c915ab4952582e4b6374c2f18d6a Mon Sep 17 00:00:00 2001 From: Georges Gomes Date: Wed, 6 Jul 2022 09:11:49 +0200 Subject: [PATCH] new options + improved documentation --- docs/.vitepress/config.ts | 2 +- docs/config/app-configs.md | 21 ++++++--------------- src/client/app/router.ts | 8 -------- src/client/app/utils.ts | 7 +------ src/client/theme-default/support/utils.ts | 6 +----- src/node/markdown/plugins/link.ts | 6 +----- types/shared.d.ts | 5 +---- 7 files changed, 11 insertions(+), 44 deletions(-) diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 39df2b0d..fc9983a3 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -8,7 +8,7 @@ export default defineConfig({ description: 'Vite & Vue powered static site generator.', lastUpdated: true, - cleanUrls: 'with-trailing-slash', + cleanUrls: 'off', themeConfig: { nav: nav(), diff --git a/docs/config/app-configs.md b/docs/config/app-configs.md index fcbe1863..b065d48b 100644 --- a/docs/config/app-configs.md +++ b/docs/config/app-configs.md @@ -175,26 +175,17 @@ export default { ## cleanUrls -- Type: `"off" | "with-trailing-slash" | "without-trailing-slash"` +- Type: `"off" | "with-subfolders"` - Default: `"off"` -When set to `"off"`, page `foo/bar.md` is generated into `foo/bar.html`. +| Option | Page | Generated page | URL | Generated 404 | +|-------------------|---------------|---------------------|--------------|----------------| +| `off` | foo/bar.md | foo/bar.html | foo/bar.html | /404.html | +| `with-subfolders` | foo/bar.md | foo/bar/index.html | foo/bar | /404.html | -When set to `"with-trailing-slash"` or `"without-trailing-slash"`, page `foo/bar.md` is generated into `foo/bar/index.html`. - -When set to `"with-trailing-slash"`, URLs will be `foo/bar/`. -When set to `"without-trailing-slash"`, URLs will be `foo/bar`. - -Notes: -- `404.md` page is kept transforming to `404.html` for hosting services. -- Also work in MPA mode. ```ts export default { - cleanUrls: "without-trailing-slash" + cleanUrls: "with-subfolders" } ``` - -### Hosting on Netlify - -Always use `"off"` or `"with-trailing-slash"` when hosted on Netlify. diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 4980dafb..81f17c4f 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -49,14 +49,6 @@ export function createRouter( url.pathname += '.html' href = url.pathname + url.search + url.hash } - } else if ( - siteDataRef.value.cleanUrls === 'with-trailing-slash' && - !url.pathname.endsWith('/') - ) { - // Clean URLs with trailing slash - // Let's add missing slashes - url.pathname += '/' - href = url.pathname + url.search + url.hash } if (inBrowser) { diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 7708cf82..91b8da5b 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -22,13 +22,8 @@ export function withBase(path: string) { export function pathToFile(path: string): string { let pagePath = path.replace(/\.html$/, '') pagePath = decodeURIComponent(pagePath) - if (siteDataRef.value.cleanUrls === 'off' && pagePath.endsWith('/')) { + if (pagePath.endsWith('/')) { pagePath += 'index' - } else if ( - siteDataRef.value.cleanUrls === 'with-trailing-slash' && - pagePath.endsWith('/') - ) { - pagePath = pagePath.slice(0, -1) } if (import.meta.env.DEV) { diff --git a/src/client/theme-default/support/utils.ts b/src/client/theme-default/support/utils.ts index 1521abee..95366113 100644 --- a/src/client/theme-default/support/utils.ts +++ b/src/client/theme-default/support/utils.ts @@ -85,11 +85,7 @@ export function normalizeLink( ? url : `${pathname.replace( /(\.md)?$/, - cleanUrls === 'off' - ? '.html' - : cleanUrls === 'with-trailing-slash' - ? '/' - : '' + cleanUrls === 'off' ? '.html' : '' )}${search}${hash}` return withBase(normalizedPath) diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index 1666e25f..64a40365 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -68,11 +68,7 @@ export const linkPlugin = ( if (cleanUrl.endsWith('.md')) { cleanUrl = cleanUrl.replace( /\.md$/, - shouldCleanUrls === 'off' - ? '.html' - : shouldCleanUrls === 'with-trailing-slash' - ? '/' - : '' + shouldCleanUrls === 'off' ? '.html' : '' ) } // transform ./foo -> ./foo[.html] diff --git a/types/shared.d.ts b/types/shared.d.ts index fe1b6477..e6aec286 100644 --- a/types/shared.d.ts +++ b/types/shared.d.ts @@ -18,10 +18,7 @@ export interface Header { slug: string } -export type cleanUrlsOptions = - | 'off' - | 'with-trailing-slash' - | 'without-trailing-slash' +export type cleanUrlsOptions = 'off' | 'with-subfolders' export interface SiteData { base: string