-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
fix (v1): fix broken relative links related to --skip-next-release
build option
#1816
fix (v1): fix broken relative links related to --skip-next-release
build option
#1816
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 8bcf10c |
Deploy preview for docusaurus-preview ready! Built with commit 8bcf10c |
@endiliey - Would it be possible for you to take a quick look at this PR? Sorry for nudging you on this. Unfortunately my documentation sites are live and have lots of broken links due to this bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have taken a look on this PR previously but my impression is that this might not be the full fix so i havent got back to it. Its been only 2 days too :(
In v1.
For the very first version being cut, it will copy all the docs into versioned_docs/version-1
On subsequent version, it creates versioned docs if and only if the docs content are different. In cases where only one doc content is different, the relative resolving wont work.
Thanks @endiliey for looking into it and the PR. I'll test out my change on the scenario mentioned about subsequent versioning changes. |
343d177
to
191044d
Compare
191044d
to
41b4fb2
Compare
--skip-next-release
build option--skip-next-release
build option
@endiliey - Would it be possible for you to review this PR again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I’m not confident this is the right fix, hence I am not inclined to merge this out because I am also not really sure what kind of other bugs could potentially surface.
I could potentially point out few problems:
- It tries to replace md with html. What if user use cleanurl
- What if the “next” docs have a different structure or some file are deleted
I think all of this actually comes down to “relative linking fails” bug.
I think the right fix is to create an imaginary folder structure (with all the fallback docs imaginatively being in each version)) Then relative linking resolve is very easy
Thanks for reviewing this @endiliey . Regarding your concerns:
I don't think I've changed the logic that takes care of
This is a valid concern, but this is actually a fundamental issue with versioning feature in V1. I believe this is one of the reasons why V2 development started (https://docusaurus.io/blog/2018/09/11/Towards-Docusaurus-2#versioning). Plus I think your concern with this is valid regardless of whether this fix is accepted or not. And that's out of the scope of this bug fix, in my opinion. Thoughts? |
I just realized that the preview site that is deployed does not use the build option |
41b4fb2
to
d1e6590
Compare
I pushed a commit yesterday after I noticed a bug in this fix. I believe there might still be a bug in here: } else if (fs.existsSync(targetFileAtRoot)) {
htmlLink = resolve(docsSource, mdMatch[1]).replace('.md', '.html');
} I can test this out and push a fix if the current approach is acceptable. |
…build option The problem is described in issue facebook#1805 and it seems to have existed for a long time. Given versioning is enabled and the repository contains versioned docs, if the build option `--skip-next-release` is used when building the static site, the versioned docs contains a lot of broken links. The generator is not able to locate the targetted file for the relative link and so it leaves the html links as ".md" instead of ".html". The issue appears to be isolated to `website/versioned-docs/` only and only if the above mentioned build option is used. This change fixes this issue and allows for generating site with appropriate relative links.
… different The previous commit would fix the borken relative links involving `--skip-next-release` when the very first/initial version is created or if **all** docs were updated before creating a version. If only a few/one doc was updated before creating a version, there would still be broken relative links when building the site with `--skip-next-release` docs. This commit fixes the issues mentioned above.
Previous commit didn't account for "invalid relative link" where the target file does not exit. This commit fixes that and also makes sure that relative links are converted even when `--skip-next-release` build option is used.
The previous commit had a bug that didn't resolve the relative link properly. Addressed that bug and also made sure that it will work if anyone uses the `cleanUrl` configuration.
d1e6590
to
8bcf10c
Compare
I believe I've resolved it in the latest commit. Please review once more. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didnt know how did I miss the notification on this PR, but I guess the request review prompted me an email.
I still think the right fix is to create an imaginary folder structure (with all the fallback docs imaginatively being in each version. Hence I'm not confident/inclined to merge this out. Every merge means taking responsibility of it if anything broke. You might want to request for other maintainers review if needed
Thanks for looking into this again.
What would be the benefit with that approach? Is there certain aspect of the current approach that is problematic?
I'm happy to work on this with your guidance. If you'd like to invite others for discussions, that's okay too 😄 |
The benefit is that it would close out all the issues of broken relative markdown linking, even if directory structure in the “next” docs folder change. Finally, the only caveat in v1 fallback versioning will only be the fact that you cant have docA.md in version 1.0.0 but no docA.md in version 1.1.0 (there is no way to delete certain old document since it will fallback) Anyway I’m working on versioning at v2 right now 😅 |
To be honest, I'm a little hesitant on tackling all issues in a single PR. I think that has the potential to be more error prone and difficult to trace issues. Anyways, what other relative linking issues are there? It'd help if I know the nature of those issues at first. Would you be able to point me to those issues?
Not sure if I have a mist-interpretation of how the versioning work in V1. My understanding is that version That's why in this PR, right now it's validating the actual file path. Even if we create an imaginary folder structure to validate the relative links, would we not need to validate whether the target file exists or not?
Can't wait to try it out 😃 . Is there anyone else who can look into this PR? I'm happy to continue with this PR but I think I will need some help and I understand you're busy on v2. |
Nah that is slightly wrong. Edit: not sure if i misunderstand your statement but anyway, Read out https://docusaurus.io/docs/en/versioning#fallback-functionality
Imagine you have a fresh new docusaurus site, no versioning yet. Only one docA.md in When you access 1.1.0 route, it's using the 1.0.0 docs. Its called fallback. Not rise back :) |
So, in this case, before I make the new version Is that right? |
yes |
Thanks. Would you be able to give me some pointers on where to start if we need to use an imaginary file/folder structure? |
cc @endiliey |
@endiliey, @yangshun - Is there any chance you'd be able to help me out with this PR? I'm not really sure where to start based on the last recommendation. To be honest, I'm also having difficulty seeing issues from the current changes in this PR. I believe I've addressed all the regression bugs since the first commit. I fully support the suggestion of "right fix". But as I mentioned previously, I don't think this PR should be resolving multiple issues especially those that appear due to the architecture of versioning feature of V1. Another problem is that I couldn't find other relevant open issues that might be related to this PR. That's why I'm not sure in what other cases/scenarios my current change will not work. Anyways, it'd be great if you could test out my current change. If I need to change the implementation logic, I need a little bit more help with pointing me to the right direction 😄 |
First of all thank you for taking your time sending a PR. I'd like to point out that reviewing takes time. I receive tons of notifications everyday and its more than possible I completely missed that.
So ultimately you want to make sure that this docusaurus/packages/docusaurus-1.x/lib/server/metadataUtils.js Lines 66 to 90 in a2c9298
I could point out another issue from this PR, even from a glance.
The fact that you changed below line is potentially a source of bug because the lines of code below no longer share same assumption - if (metadata.language !== 'en' || metadata.original_id) {
+ if (metadata.language !== 'en') { Take the next line for example. let htmlLink = baseUrl + metadata.permalink.replace('/next/', '/'); If one of your docs is named you need to change the whole logic below of it to ensure its not buggy I don't know what kind of other bug it can introduce. That's why I wont prefer a PR that only solve a small issue but is introducing another issue. Take #1869 that looks harmless for example, its causing another bug now.
Testing out change takes time. I'd prefer you write tests for it and I will be confident to merge it out. If i have to point out every several issues that might arise, its just gonna take my time which is better spent on v2 |
Thanks @endiliey for your feedback and time. I really appreciate it. I will go through your suggestions and see if I can come up with a different approach. Question on the following change when you get a chance: - if (metadata.language !== 'en' || metadata.original_id) {
+ if (metadata.language !== 'en') { Why is the above change incorrect or should remain as-is? Currently the
Yes, I agree with you on this one. But, I think this is not a new issue. I believe the way versioning works in V1 at the moment, you can't have documents in a directory named It's also kind of impractical in my opinion because that's like saying, what if a user decided to name one of the directories using language code. For example, has docs under |
Yeah im not saying it should remain as it is. But just pointing it out that if want to fix that, might as well fix that part. A right fix is better than a partial fix. Edit: also my point is that if you edit below, you need to edit all of below as well - if (metadata.language !== 'en' || metadata.original_id) {
+ if (metadata.language !== 'en') { docusaurus/packages/docusaurus-1.x/lib/server/metadataUtils.js Lines 83 to 85 in 2d15fad
|
What im saying is the right fix is to revamp the mdToHtml such that we can create the mapping correctly that doesnt depends on next docs |
I understand. To me it looks like the right fix would require changing how versioning works in V1. But that's what V2 is for 😄 |
@endiliey - I didn't get a chance to look at this in last few days. I wanted to get your feedback before diving into any code change. Right now, Docusaurus generates a "metadata" file here: https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-1.x/lib/server/generate.js#L57-L60 This generated file is then fed into
You suggested generating a virtual directory structure and then resolve relative links. How would you go about generating this directory structure? We can't use the generated "metadata" file because it will not contain the "next release" docs. And in that case, we won't be able to resolve relative links that depends on files that are in the "next release" because those files were not copied over at the time of creation of the version. Would you be able to clarify how you would create the imaginary folder structure with all the fallback docs being in each version? |
@endiliey - Thanks for the detailed example and clarifying that fallback shouldn't depend on next release docs. Should I continue to look for a fix for this? If it's decided that certain issues in V1 will not be fixed, then it's probably going to save some time for both of us 😄 |
If you can send a fix like above, I will gladly accept it 😆. But i do need someone’s else approval too. But I think you are right, we can both save our time :). Why not try in v2 or contribute to it 😀 |
Lets close this up for now assuming you're not working on it. Thanks for the attempt btw 😉 |
Unfortunately I got a little busy with other work and didn't get a chance to come back to this again. I can try this again, if you'd like. I looked into the version fallback briefly and realized that has info on all of the versioned doc's and their corresponding source. I think that can be used to validate if the target link exists in that fallback source. What do you think? |
@endiliey - I decided to take another attempt at it. Since this PR is already closed, please take a look at the changes in here: I think this is a simpler fix compared to my previous attempts and it doesn't rely on accessing files to validate links. I believe it also fixes #1774 If you're interested in reviewing this change further, I'll open another PR. Thank you for your time. |
@endiliey - Just checking if you can look review the above change. I think the current change aligns with the Version Fallback mechanism now. BTW - Happy new year. Hope you've had a good holiday. |
@yangshun - I learned the sad news about Endi leaving us through the recent release of V1. He had been guiding me on this PR for "right fix". Initially I had some misunderstanding about how the version fallback worked. I tried to find a proper fix but wasn't quick enough to be able to get Endi's feedback. Is this something you can look into? Should I open a separate PR or are you able to re-open this? |
I really don't think it's worth working on this at this point. We don't
want to add new things to v1 and would only focus on v2.
…On Sat, Jan 18, 2020, 2:53 AM PA ***@***.***> wrote:
@yangshun <https://github.com/yangshun> - I learned the sad news about
Endi leaving us through the recent release of V1. He had been guiding me on
this PR for "right fix". Initially I had some misunderstanding about how
the version fallback worked.
I tried to find a proper fix but wasn't quick enough to be able to get
Endi's feedback. Is this something you can look into? Should I open a
separate PR or are you able to re-open this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1816?email_source=notifications&email_token=AAKBCHL4X62IZH2U62KXYPTQ6H5BVA5CNFSM4I6VSZWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJIUDPA#issuecomment-575750588>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKBCHOVWP3ZX6ELDRDDTMDQ6H5BVANCNFSM4I6VSZWA>
.
|
Thanks for your reply @yangshun This isn't actually anything new for v1; it's a bug fix. It would probably make sense to freeze changes in v1, if v2 was production ready but that's not the case as of this moment. Anyways, ultimately it's your decision. Thanks again for your time. |
The problem is described in issue #1805 and it seems to have existed for a long time.
Given versioning is enabled and the repository contains versioned docs, if the build
option
--skip-next-release
is used when building the static site, the versioneddocs contains a lot of broken links. The generator is not able to locate the targetted
file for the relative link and so it leaves the html links as ".md" instead of ".html".
The issue appears to be isolated to
website/versioned-docs/
only and only if the abovementioned build option is used.
This change fixes this issue and allows for generating site with appropriate relative
links.
closes #1805
Motivation
I have used Docusaurus in several of my work related documentation sites. We've recently published our documentation sites and found out about this bug. Currently our production sites has lot of broken links in our "versioned docs".
I wanted to see a proper fix that will work for everyone instead of coming up with a workaround or hacking our sites post-build to address this issue.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)
The changes in this PR is relatively small. So, I applied these changes to my documentation projects where I have the bugs. Then:
yarn build
yarn build --skip-next-release
I know that V2 is still under development but I wasn't able to find any code related to this feature.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)