-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support Root-Relative Links (Absolute Links)? #57
Comments
interesting! This project is very much for stuff hosted on github/gitlab/bitbucket. So, repositories, that link to other markdown files in that repository. I think we even support such URLs, but in the way that |
Aha, I guess these are root-relative links to GitHub then? These I would actually count as "external links", but I can see how they have all of the characteristics of a normal root-relative link. I think that the 95% case can probably be handled with a general resolution scheme, with a configuration option of For example, this configuration... module.exports = {
plugins: [
[
"remark-validate-links",
{
baseDir: '/remarkjs/remark-validate-links',
},
],
],
} ...along with this link in Markdown... [link](/remarkjs/remark-validate-links/docs/configuration) ...would search for the following files in the repo to see if it will be a broken link:
This would allow for a lot of cases for Markdown projects, both:
However, since your library has a focus on these platforms, there could be two or more special cases added for these platforms: 1. Add check for
|
Oh, just reading in remark-validate-links/lib/find/find.js Lines 190 to 223 in ca235ff
|
So I suppose the changes proposed by this issue would have to be somewhere in here: remark-validate-links/lib/find/find.js Lines 190 to 215 in ca235ff
Specifically, to add a separate branch that would resolve root-relative links to file paths with |
Say I have a {
"name": "example",
"scripts": {
"test": "remark ."
},
"remarkConfig": {
"plugins": [
[
"validate-links",
{
"repo": "x/y"
}
]
]
},
"devDependencies": {
"remark-cli": "^8.0.1",
"remark-validate-links": "^10.0.2"
}
} A [a](/x/y/blob/main/docs/non-existent/)
[b](/x/y/blob/main/docs/exists/#readme)
[c](/x/y/blob/main/docs/exists/#non-existent2) And a Hi! Now, running
As you can see, the links are checked. This is to say, we do support full urls with a hostname ( What you mention here:
That sort of works as shown above, but it does that with So, I’d say the question, support root-relative links (absolute links), is already solved. Just in a different way than what you expected. Thus, to come back to the original problem
Can you tell me more about this? |
Sure. Here's an example:
With any sort of renaming or structure changes, it can lead to a lot of error-prone manual work, if there is no automation such as a link checker involved (and users want the guarantees mentioned in point 5). Does this clarify anything? |
I ended up building this CLI tool in the meantime: https://github.com/upleveled/mdx-local-link-checker This supports links to local MDX files, along with the following features:
# Check the current directory with no ignore patterns
mdx-local-link-checker
# Check the src/pages folder, ignoring anything in a
# folder called "books" (at any depth)
mdx-local-link-checker src/pages src/pages "/books/**"
# Check the src/pages folder, ignoring anything in a
# folder called "books" or "slide-decks" (at any depth)
mdx-local-link-checker src/pages src/pages "/(books|slide-decks)/**"
# Check only the docs folder with the src/pages
# folder set to be the base path (for root-relative
# links such as "/docs/router")
mdx-local-link-checker src/pages/docs src/pages |
So in case Config: baseDir: '/src/pages',
extension: 'mdx',
To read more, check out [the docs](/lib-2/docs) about `lib-2`! The link above would be resolved to the file (maybe the |
Having this feature would be extremely useful, especially in monorepos where some markdowns reference other projects. Any news on this? 👀 |
Absolute paths are now supported like GitHub again, per #75. |
Hi @wooorm ! 👋
Subject of the feature
What do you think about supporting root-relative links such as in the example below?
I suppose this could be configured with a configuration option, maybe named like
basedir
.Problem
On large sites with a lot of moving files or large directory structures, updating relative links can be a pain.
Root relative links can also avoid any ambiguity that can be caused by using the same path ending and file name between multiple files.
Expected behaviour
It would be nice for these links to also be checked.
Alternatives
gatsby-remark-check-links, but:
gh-action-check-broken-links, but:
pages
directoryThe text was updated successfully, but these errors were encountered: