Skip to content
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

Enabling External Link Validity Checking #4009

Open
4 tasks done
slusarz opened this issue Jul 1, 2024 · 2 comments
Open
4 tasks done

Enabling External Link Validity Checking #4009

slusarz opened this issue Jul 1, 2024 · 2 comments
Labels
enhancement New feature or request has-workaround Has workaround, low priority

Comments

@slusarz
Copy link

slusarz commented Jul 1, 2024

Is your feature request related to a problem? Please describe.

During build (or CI) process, external links should be checked for validity.

Currently, VP only checks localhost links. Other external links are just added as-is to the page. See

// catch localhost links as dead link

Describe the solution you'd like

At a minimum, ignoreDeadLinks callback option should be extended to return ALL links seen during parsing. VP admin can then write their own logic to do link checking.

Example:

ignoreDeadLinks: [
    (url) => {
        if (external_URL) {
            // Do link checking, i.e. with 'link-check' npm package
        } elseif (localhost_URL) {
            // Handle localhost checking.
        }
    }
],

Even better would be a way to continue to allow VP to handle localhost link checking and provide an option to handle external links separately.

Even even better might be that external link checking is simply built-in to VP, as an option. (E.g., Sphinx has this ability.). Simple example:

import 'linkCheck' from 'link-check'

// ...

linkCheck(url_to_check, function (err, result) {
    if (err) {
        throw new Error('Invalid Link: ' + err)
    }
});

Describe alternatives you've considered

No response

Additional context

More than willing to provide an MR to accomplish this, but since there are so many possibilities on how to allow/enable this I would rather wait for developer input to direct towards the best solution.

Validations

@brc-dd
Copy link
Member

brc-dd commented Jul 1, 2024

Might be easy to just run lychee or one of the tools mentioned here - https://github.com/lycheeverse/lychee?tab=readme-ov-file#features -- most of these are CLIs and integrating directly in vitepress won't make much sense and will slow you down.

Also, ignoreDeadLinks can't receive the external links because many of these links cannot be extracted by the markdown parser - for example links added via components, html tags, frontmatter, themeConfig, etc.

@brc-dd brc-dd added enhancement New feature or request has-workaround Has workaround, low priority labels Jul 1, 2024
@slusarz
Copy link
Author

slusarz commented Jul 1, 2024

Appreciate the quick response and the pointer to the lychee project (that looks fantastic for our use-case...)

Understood now that the existing ignoreDeadLinks is not built for this ask.

More than willing to do a small MR for documentation that would adapt your explanation, if you think that would be helpful (I have to think we are not the only ones who are looking for this functionality).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has-workaround Has workaround, low priority
Projects
None yet
Development

No branches or pull requests

2 participants