-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
531 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
meta: | ||
a: 0 | ||
c: 3 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { h } from 'vue' | ||
import type { FunctionalComponent, VNode } from 'vue' | ||
import { useRouter } from 'vue-router' | ||
import { pagesMap, redirectsMap } from '../composables/index.js' | ||
import { withBase } from '../helpers/index.js' | ||
import { resolvers } from '../resolvers.js' | ||
|
||
/** | ||
* Forked from https://github.com/vuejs/router/blob/941b2131e80550009e5221d4db9f366b1fea3fd5/packages/router/src/RouterLink.ts#L293 | ||
*/ | ||
const guardEvent = (event: MouseEvent): boolean | void => { | ||
// don't redirect with control keys | ||
if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey) return | ||
// don't redirect when preventDefault called | ||
if (event.defaultPrevented) return | ||
// don't redirect on right click | ||
if (event.button !== undefined && event.button !== 0) return | ||
// don't redirect if `target="_blank"` | ||
if (event.currentTarget) { | ||
const target = (event.currentTarget as HTMLElement).getAttribute('target') | ||
if (target?.match(/\b_blank\b/i)) return | ||
} | ||
event.preventDefault() | ||
return true | ||
} | ||
|
||
interface VPLinkProps { | ||
to: string | ||
} | ||
|
||
export const VPLink: FunctionalComponent< | ||
VPLinkProps, | ||
Record<never, never>, | ||
{ | ||
default: () => string | VNode | (string | VNode)[] | ||
} | ||
> = ({ to = '' }, { slots }) => { | ||
const router = useRouter() | ||
const path = withBase( | ||
resolvers.resolvePagePath(pagesMap.value, redirectsMap.value, to), | ||
) | ||
|
||
return h( | ||
'a', | ||
{ | ||
class: 'vp-link', | ||
href: path, | ||
onClick: (event: MouseEvent = {} as MouseEvent) => { | ||
guardEvent(event) ? router.push(to).catch() : Promise.resolve() | ||
}, | ||
}, | ||
slots.default?.(), | ||
) | ||
} | ||
|
||
VPLink.displayName = 'VPLink' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './ClientOnly.js' | ||
export * from './Content.js' | ||
export * from './VPLink.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
pagesMap as pagesMapRaw, | ||
redirectsMap as redirectsMapRaw, | ||
} from '@internal/pagesMap' | ||
import type { PageRedirectsMap, PagesMap } from '@internal/pagesMap' | ||
import { shallowRef } from 'vue' | ||
import type { Ref } from 'vue' | ||
|
||
/** | ||
* Ref wrapper of `PagesMap` | ||
*/ | ||
export type PagesMapRef = Ref<PagesMap> | ||
|
||
/** | ||
* Ref wrapper of `PageRedirectMap` | ||
*/ | ||
export type PageRedirectsRef = Ref<PageRedirectsMap> | ||
|
||
/** | ||
* Global pages map ref | ||
*/ | ||
export const pagesMap: PagesMapRef = shallowRef(pagesMapRaw) | ||
|
||
/** | ||
* Global pages map ref | ||
*/ | ||
export const redirectsMap: PageRedirectsRef = shallowRef(redirectsMapRaw) | ||
|
||
/** | ||
* Returns the ref of pages map | ||
*/ | ||
export const usePagesMap = (): PagesMapRef => pagesMap | ||
|
||
/** | ||
* Returns the ref of pages map | ||
*/ | ||
export const useRedirectsMap = (): PageRedirectsRef => redirectsMap | ||
|
||
if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) { | ||
// reuse vue HMR runtime | ||
__VUE_HMR_RUNTIME__.updatePageRedirectsMap = (data: PageRedirectsMap) => { | ||
redirectsMap.value = data | ||
} | ||
__VUE_HMR_RUNTIME__.updatePagesMap = (data: PagesMap) => { | ||
pagesMap.value = data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.