fix: remove dependency of localhost url testing on EXTERNAL_URL_RE

pull/503/head
Divyansh Singh 4 years ago
parent 708954644d
commit 423d965103

@ -5,7 +5,7 @@
import MarkdownIt from 'markdown-it' import MarkdownIt from 'markdown-it'
import { MarkdownRenderer } from '../markdown' import { MarkdownRenderer } from '../markdown'
import { URL } from 'url' import { URL } from 'url'
import { EXTERNAL_URL_RE } from '../../shared' import { EXTERNAL_URL_RE, LOCALHOST_URL_RE } from '../../shared'
const indexRE = /(^|.*\/)index.md(#?.*)$/i const indexRE = /(^|.*\/)index.md(#?.*)$/i
@ -25,7 +25,7 @@ export const linkPlugin = (
token.attrSet(key, val) token.attrSet(key, val)
}) })
// catch localhost links as dead link // catch localhost links as dead link
if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) { if (LOCALHOST_URL_RE.test(url)) {
pushLink(url) pushLink(url)
} }
} else if ( } else if (

@ -4,7 +4,7 @@ import matter from 'gray-matter'
import LRUCache from 'lru-cache' import LRUCache from 'lru-cache'
import { createMarkdownRenderer, MarkdownOptions } from './markdown/markdown' import { createMarkdownRenderer, MarkdownOptions } from './markdown/markdown'
import { deeplyParseHeader } from './utils/parseHeader' import { deeplyParseHeader } from './utils/parseHeader'
import { PageData, HeadConfig, EXTERNAL_URL_RE } from './shared' import { PageData, HeadConfig, LOCALHOST_URL_RE } from './shared'
import { slash } from './utils/slash' import { slash } from './utils/slash'
import chalk from 'chalk' import chalk from 'chalk'
import _debug from 'debug' import _debug from 'debug'
@ -104,7 +104,7 @@ export function createMarkdownToVueRenderFn(
if (data.links) { if (data.links) {
const dir = path.dirname(file) const dir = path.dirname(file)
for (let url of data.links) { for (let url of data.links) {
if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) { if (LOCALHOST_URL_RE.test(url)) {
recordDeadLink(url) recordDeadLink(url)
continue continue
} }

@ -10,6 +10,7 @@ export type {
} from '../../types/shared' } from '../../types/shared'
export const EXTERNAL_URL_RE = /:\/\/|\.(?!html|md)\w+$/i export const EXTERNAL_URL_RE = /:\/\/|\.(?!html|md)\w+$/i
export const LOCALHOST_URL_RE = /:\/\/localhost:/
// @ts-ignore // @ts-ignore
export const inBrowser = typeof window !== 'undefined' export const inBrowser = typeof window !== 'undefined'

Loading…
Cancel
Save