Skip to content

Commit 4a34b93

Browse files
committed
refactor: reuse regexp
1 parent 6c2c0f0 commit 4a34b93

File tree

2 files changed

+4
-2
lines changed
  • src

2 files changed

+4
-2
lines changed

src/client/theme-default/composables/repo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { computed } from 'vue'
22
import { useData } from 'vitepress'
33
import type { DefaultTheme } from '../config'
4+
import { EXTERNAL_URL_RE } from '../../shared'
45

56
export const platforms = ['GitHub', 'GitLab', 'Bitbucket'].map((platform) => {
67
return [platform, new RegExp(platform, 'i')] as const
@@ -26,7 +27,7 @@ export function useRepo() {
2627

2728
function getRepoUrl(repo: string): string {
2829
// if the full url is not provided, default to GitHub repo
29-
return /^https?:/.test(repo) ? repo : `https://github.com/${repo}`
30+
return EXTERNAL_URL_RE.test(repo) ? repo : `https://github.com/${repo}`
3031
}
3132

3233
function getRepoText(url: string, text?: string): string {

src/node/markdown/plugins/link.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import MarkdownIt from 'markdown-it'
66
import { MarkdownParsedData } from '../markdown'
77
import { URL } from 'url'
8+
import { EXTERNAL_URL_RE } from '../../shared'
89

910
const indexRE = /(^|.*\/)index.md(#?.*)$/i
1011

@@ -18,7 +19,7 @@ export const linkPlugin = (
1819
if (hrefIndex >= 0) {
1920
const hrefAttr = token.attrs![hrefIndex]
2021
const url = hrefAttr[1]
21-
const isExternal = /^https?:/.test(url)
22+
const isExternal = EXTERNAL_URL_RE.test(url)
2223
if (isExternal) {
2324
Object.entries(externalAttrs).forEach(([key, val]) => {
2425
token.attrSet(key, val)

0 commit comments

Comments
 (0)