-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Improve resolution of relative links to files not in the website #6463
Comments
The broken links check happens at a much later stage than the Markdown link resolution, so we unfortunately can't do that. You still have to be explicit in telling Docusaurus that it's a file path, e.g. by prepending |
@Josh-Cena what about idea number 2 then? Always link with |
Mmm, that sounds like a problem very close to #6210. TL;DR: |
Ok. If there was a way to check for broken links earlier... something like:
But as you said, pages are not only made of |
The problem is that there are a bunch of other pages that are not generated with Markdown, e.g. React pages, plugin-created dynamic pages, that can only be reliably detected once we build the site, which happens after the Markdown transformation is done. No problem if we can't think of a viable solution yet. This could be interesting to work on, maybe we can check in the FS for a corresponding file first. About making the site work in the GitHub interface though, that has never been our priority, although it's usually a nice thing to stick to. So if we decided it can only be reliably done by sacrificing usability on GitHub, we will do it. |
Totally understood. |
We don't to anything special with such link, we just render Note that when you write: @felipecrs what I understand is that you want to create a download link to the Dockerfile right? How can Docusaurus easily understand that you want to download a file, instead of navigating? You could have a page with Here Some things worth giving a try: This should create a download link: The source code is available at [Dockerfile](@site/../Dockerfile) This should navigate the current page to the Dockerfile, with regular HTML navigation (no SPA 404/broken link reported): The source code is available at [Dockerfile](pathname://../../Dockerfile) |
Note you may also like to display the dockerfile content directly as a code block in your docs: https://docusaurus.io/docs/markdown-features/react#importing-code-snippets |
Not really, I just want to link to the regular file in GitHub (or whatever other "baseUrl" I select). Example: https://github.com/felipecrs/jenkins-agent-dind/blob/master/Dockerfile (it's not meant to be downloaded, but to be viewed) Regardless, I'm not saying Docusaurus is doing anything wrong. I'm just proposing something that in my view would be nice. Perhaps, as @Josh-Cena, we can use a prefix to tell Docusaurus when to apply the The source code is available at [Dockerfile](file://../../Dockerfile). |
What I suggest is that you build (or find an existing one) a remark plugin to rewrite the links to whatever you want Here's an inspiration to process md links: https://github.com/remarkjs/remark-external-links/blob/main/index.js You could replace: The source code is available at [Dockerfile](../../Dockerfile). with The source code is available at [Dockerfile](https://xyz.com/Dockerfile). Now it's up to you to provide your own conversion logic |
Oh, that makes sense! I think we don't need to implement this in the core, since making a Remark plugin is pretty easy and flexible |
Have you read the Contributing Guidelines on issues?
Motivation
Refs #6460 (reply in thread).
The proposal is to make Docusaurus smarter on how it handles relative links to files which are not included on the website itself. To be clear about what I'm referring to:
Let's say you have a
docs/docker-images/index.md
with something like:Docusaurus will try to link to this file in my website itself (http://localhost:3000/docs/../../Dockerfile -> ?). Which, in turn, is broken link. Instead, for such situations, Docusaurus could link to the file in the source code browser.
Technically, I'm talking about something like below:
Namely look at
relativeFilesBaseUrl
. This would tell Docusaurus to use this base URL instead of the website itself to link relative files (which otherwise would be broken links). Some examples:Of course, one possible workaround is to do something like:
But the proposed solution would have the benefit of:
About how to determine whether a file should be linked using
relativeFilesBaseUrl
or the normal website linking, I have some ideas:relativeFilesBaseUrl
. If not, throw broken link as before.relativeFilesBaseUrl
unless the link is a.md
file which is known to be valid and included in the website. But, of course, check if the file exists before, and if not, throw a broken link as before.docs/foo/bar
(no.md
extensions). I would suggest that, if one enabledrelativeFilesBaseUrl
, Docusaurus won't try to add.md
proactively and instead would treat as a full file name directly. Linking to.md
files without using their extensions is already discouraged by Docusaurus anyway.Self-service
The text was updated successfully, but these errors were encountered: