Skip to content

Commit

Permalink
feat: don't add .html to urls
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Jun 5, 2022
1 parent 1fe5153 commit 89cc718
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/guide/migration-from-vitepress-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you're coming from VitePress 0.x version, there're several breaking changes d
- `children` key is now named `items`.
- Top level item may not contain `link` at the moment. We're planning to bring it back.
- `repo`, `repoLabel`, `docsDir`, `docsBranch`, `editLinks`, `editLinkText` are removed in favor of more flexible api.
- For adding GitHub link with icon to the nav, use [Social Links](./theme-nav.html#navigation-links) feature.
- For adding GitHub link with icon to the nav, use [Social Links](./theme-nav#navigation-links) feature.
- For adding "Edit this page" feature, use [Edit Link](./theme-edit-link) feature.
- `lastUpdated` option is now split into `config.lastUpdated` and `themeConfig.lastUpdatedText`.
- `carbonAds.carbon` is changed to `carbonAds.code`.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/theme-nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The Nav is the navigation bar displayed on top of the page. It contains the site

## Site Title and Logo

By default, nav shows the title of the site refferencing [`config.title`](../config/app-configs.html#title) value. If you would like to change what's displayed on nav, you may define custom text in `themeConfig.siteTitle` option.
By default, nav shows the title of the site refferencing [`config.title`](../config/app-configs#title) value. If you would like to change what's displayed on nav, you may define custom text in `themeConfig.siteTitle` option.

```js
export default {
Expand Down
6 changes: 0 additions & 6 deletions src/client/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ export function createRouter(
const route = reactive(getDefaultRoute())

function go(href: string = inBrowser ? location.href : '/') {
// ensure correct deep link so page refresh lands on correct files.
const url = new URL(href, fakeHost)
if (!url.pathname.endsWith('/') && !url.pathname.endsWith('.html')) {
url.pathname += '.html'
href = url.pathname + url.search + url.hash
}
if (inBrowser) {
// save scroll position before changing url
history.replaceState({ scrollPosition: window.scrollY }, document.title)
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function pathToFile(path: string): string {
// /foo/bar.html -> ./foo_bar.md
if (inBrowser) {
const base = import.meta.env.BASE_URL
pagePath = pagePath.slice(base.length).replace(/\//g, '_') + '.md'
pagePath =
(pagePath.slice(base.length).replace(/\//g, '_') || 'index') + '.md'
// client production build needs to account for page hash, which is
// injected directly in the page's html
const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()]
Expand Down
2 changes: 1 addition & 1 deletion src/client/theme-default/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function normalizeLink(url: string): string {
const normalizedPath =
pathname.endsWith('/') || pathname.endsWith('.html')
? url
: `${pathname.replace(/(\.md)?$/, '.html')}${search}${hash}`
: `${pathname.replace(/(\.md)?$/, '')}${search}${hash}`

return withBase(normalizedPath)
}
10 changes: 1 addition & 9 deletions src/node/markdown/plugins/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ export const linkPlugin = (
const [, path, hash] = indexMatch
url = path + hash
} else {
let cleanUrl = url.replace(/[?#].*$/, '')
// .md -> .html
if (cleanUrl.endsWith('.md')) {
cleanUrl = cleanUrl.replace(/\.md$/, '.html')
}
// ./foo -> ./foo.html
if (!cleanUrl.endsWith('.html') && !cleanUrl.endsWith('/')) {
cleanUrl += '.html'
}
const cleanUrl = url.replace(/[?#].*$/, '').replace(/\.md$/, '')
const parsed = new URL(url, 'http://a.com')
url = cleanUrl + parsed.search + parsed.hash
}
Expand Down

0 comments on commit 89cc718

Please sign in to comment.