-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected One or more pages contain dead links
for localhost
links
#822
Comments
I have to use |
Do you know why localhost is considered a dead link? In my opinion local links like localhost and 127.0.0.1 should not be considered as dead links, they are valid in some development, internal scenarios. vitepress/src/node/markdown/plugins/link.ts Lines 28 to 31 in 06ad0d8
|
@kecrily Some people unintentionally leave links like Does |
Noop, it's still a link. |
@JounQin Are you sure? Because I'm not getting any error on doing that: https://stackblitz.com/edit/vite-jhbvp5?file=docs/index.md . Maybe you've those links in other files too? |
Ah, sorry, I misremembered it with
|
So, that's a recommended workaround for now (you won't have many such URLs anyway). When #793 gets merged, you can also ignore dead links check (not recommended, but will work). I don't think there is a way to actually fix this issue without disregarding the original cause why that check was introduced in first place. |
Maybe adding this limitation into document would help. Closing for now because it is |
Additionally, the |
@brc-dd I found another interested thing: // components/ExternalLink.ts, registered as global components
import type { AnchorHTMLAttributes } from 'react'
import { h, FunctionalComponent } from 'vue'
export type ExternalLinkProps = Omit<
AnchorHTMLAttributes<HTMLAnchorElement>,
'target'
>
export const ExternalLink: FunctionalComponent<ExternalLinkProps> = (
props,
context,
) =>
h(
'a',
{
target: '_blank',
rel: 'noreferrer noopener',
...props,
},
context.slots.default?.(),
) The following will still emit error. <ExternalLink href="http://localhost:3000">http://localhost:3000</ExternalLink> Because the emitted result is: <a target="_blank" rel="noreferrer noopener" href="http://localhost:3000">
<a href="http://localhost:3000" target="_blank" rel="noopener noreferrer">
http://localhost:3000
</a>
</a> I'm not sure to understand this. |
It's getting autolinked IG. Pass it as a prop instead, or disable autolinking: export default {
markdown: {
linkify: false
}
} |
Just found I was silly, I should use import type { AnchorHTMLAttributes } from 'react'
import type { FunctionalComponent } from 'vue'
import { h } from 'vue'
export interface ExternalLinkProps
extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'target'> {
href: string
}
export const LOCAL_URL_REG = /^https?:\/\/localhost:/
/**
* @see https://github.com/vuejs/vitepress/issues/822 for details
*/
export const ExternalLink: FunctionalComponent<ExternalLinkProps> = ({
href,
...props
}) => {
if (process.env.NODE_ENV === 'development' && !LOCAL_URL_REG.test(href)) {
console.error('You should use markdown style link instead')
}
return h(
'a',
{
href,
target: '_blank',
rel: 'noreferrer noopener',
...props,
},
href,
)
} <ExternalLink href="http://localhost:3000" /> |
Describe the bug
Reproduction
N/A
Expected behavior
No error
System Info
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: