fix: treat all URI schemes as external (#945) (#946)

pull/948/head
Divyansh Singh 2 years ago committed by GitHub
parent 95a74e58a4
commit 1e9a7ac6c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import { normalizeLink } from '../support/utils'
import { EXTERNAL_URL_RE } from '../../shared'
const props = defineProps<{
tag?: string
@ -15,7 +16,7 @@ const classes = computed(() => [
props.theme ?? 'brand'
])
const isExternal = computed(() => props.href && /^[a-z]+:/i.test(props.href))
const isExternal = computed(() => props.href && EXTERNAL_URL_RE.test(props.href))
const component = computed(() => {
if (props.tag) {

@ -2,13 +2,14 @@
import { computed } from 'vue'
import { normalizeLink } from '../support/utils'
import VPIconExternalLink from './icons/VPIconExternalLink.vue'
import { EXTERNAL_URL_RE } from '../../shared'
const props = defineProps<{
href?: string
noIcon?: boolean
}>()
const isExternal = computed(() => props.href && /^[a-z]+:/i.test(props.href))
const isExternal = computed(() => props.href && EXTERNAL_URL_RE.test(props.href))
</script>
<template>

@ -1,15 +1,15 @@
import { ref } from 'vue'
import { withBase } from 'vitepress'
import { EXTERNAL_URL_RE } from '../../shared'
export const HASH_RE = /#.*$/
export const EXT_RE = /(index)?\.(md|html)$/
export const OUTBOUND_RE = /^[a-z]+:/i
const inBrowser = typeof window !== 'undefined'
const hashRef = ref(inBrowser ? location.hash : '')
export function isExternal(path: string): boolean {
return OUTBOUND_RE.test(path)
return EXTERNAL_URL_RE.test(path)
}
export function throttleAndDebounce(fn: () => void, delay: number): () => void {

@ -10,7 +10,7 @@ export type {
PageDataPayload
} from '../../types/shared'
export const EXTERNAL_URL_RE = /^https?:/i
export const EXTERNAL_URL_RE = /^[a-z]+:/i
export const APPEARANCE_KEY = 'vitepress-theme-appearance'
// @ts-ignore

@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"lib": ["ESNext", "DOM"]

Loading…
Cancel
Save