new options + improved documentation

pull/869/head
Georges Gomes 3 years ago
parent 63d0acc5f2
commit 982d6bff2a

@ -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(),

@ -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.

@ -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) {

@ -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) {

@ -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)

@ -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]

5
types/shared.d.ts vendored

@ -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<ThemeConfig = any> {
base: string

Loading…
Cancel
Save