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
relative URL rewrites don't work when the default branch is not master
but eg. main
#5068
Comments
We do have a limited support for relative URL rewrites if the homepage/repository url is on GitHub or GitLab. What's the package where you have the non-working example? |
Hey @isoos, thanks for your reply. The package where it's not working is ably_flutter's 1.2.2-preview.1. You can find the spot by searching for |
The issue here is the default branch: I'll update the title of the issue, as we definitely want to fix this eventually. |
images/dog.png
)master
I'm not able to find a way to directly query the name of the main branch - but we can query the existence of master/main. I think we can do it like this:
If See api doc here: https://docs.github.com/en/rest/reference/git#get-a-reference |
@sigurdm would this be helpful?: How do I find the default branch for a repository using the Github v3 API Edit: Actually if you list organization repositories:
|
master
master
but eg. main
A cheap workaround would be to link to HEAD: https://github.com/dart-lang/pub/tree/HEAD/lib/src - it shows up a bit funny however (shows the sha-id instead of a branch name). |
I just discovered this issue while publishing a package: https://pub.dev/packages/recipe_flavored_markdown. The coverage badge (which is a relative link inside the readme markdown) is broken on pub.dev, but working on GitHub. I noticed that pub.dev is rewriting the url to point to I would think this might be fixed by now since |
It's not entirely clear how the link for the "Example" tab is generated. Some packages (eg https://pub.dev/packages/flutter_markdown) use the "main" branch, others (eg https://pub.dev/packages/path) use the "master" branch. Both in the first and in the second case, the correct branches are selected. However, for my package (https://pub.dev/packages/utf8decoder_hw) "master" is used when it should be "main", which causes the "Branch not found, redirected to default branch" box to appear. |
@chykon: We have an experimental analysis of git repositories enabled for select packages, and their analysis result are already showing the correct branch on |
Is it documented somewhere? The official docs on Writing package pages still points out using absolute URLs (what we do not want - this whole issue is opened for that). After experimenting with publishing some packages this wich (partly) works for me:
These seem allowing pub.dev to rewrite the relative links in README.md files correctly even for packages hosted in a monorepo. I wrote that it works partly because it only fixes the README.md files published to pub.dev, see images and links now rendered correctly: BUT it does not fix the generated API reference docs: Those links does not seem to have any URL rewrites, they are left relative URLs as they were in the source README.md files: So, I am happy that all my README.md files with relative URLs in my monorepo are rendered correctly now on pub.dev, but it would be even better if someone could help how to have even the API references rendered correctly. |
Not yet. The repository verification has been implemented, and we are waiting for a rollout of sandboxed analysis (also implemented, but rollout is blocked by minor infrastructure questions). Once these issues are resolved, we will have the following:
In short, it will work as you would expect without any extra effort on the developer's side, with any default branch name, or any location inside the repository. However, we ask for a bit more patience as the rollout of this happens slower than we have anticipated earlier. |
Will it also handle the generated API reference? Today it seems no rewrite happens there.
Your work is appreciated. Better to make it right than make it fast. |
Eventually it will. We have plans for it, and it should happen, but not in the immediate future. |
I also have issues with relative images and found out that it forces the I will just link this issue to #6382, as it might be part of it. |
This is now obsolete, as we rely on the repository verification (if available) which also reports the default branch. |
Problem
Local paths referenced in a GitHub readme are broken once shown on pub.dev. For example:
Current workarounds
Currently, packages work around this by using
https://github.com/
orhttps://raw.githubusercontent.com/
to reference local images in the repo. However, this means:main
/master
in the URL, so that it works once merged. This is a slightly poor developer experience.For example, flutter_local_notifications uses
<img height="480" src="https://github.com/MaikuB/flutter_local_notifications/raw/master/images/android_notification.png">
. Getx uses![](https://raw.githubusercontent.com/jonataslaw/getx-community/master/getx.png)
.Suggestion
If we changed the local paths automatically to
https://raw.githubusercontent.com/$user/$repo/branch/$relative_path
, this problem would be avoided, and it work seamlessly for users. Alternatively, we could usehttps://github.com/$user/$repo/branch/$relative_path
. There doesn't seem to be a difference for images, but there is for normal files, so github.com would probably be better?Concerns:
The text was updated successfully, but these errors were encountered: