-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
HTML Pipeline filter to make all relative urls absolute #12
Conversation
@bkeepers I'm having trouble following what's going on in github/opensource.guide#315 and github/opensource.guide#307. Before we jump to the solution, can you share a bit more context around what you're trying to accomplish, what you tried, what's not working, etc.? |
I want all of the links and images in markdown to work, whether it's rendered on GitHub Pages or GitHub.com. Given this directory layout:
Scenario 1:
This works fine on GitHub.com, because the Scenario 2:Ok, we can fix that by switching the relative image in
This works fine on GitHub.com, because it uses a filter similar to this one that makes all absolute urls relative to the repository, and it works fine when served from jekyll without a baseurl. But when you add a baseurl (e.g. someone forks your site and renders it on The solutionA jekyll site currently has to do a lot of gymnastics with the The filter added in this PR would make it so content and templates use absolute urls everywhere and it always works, whether it's rendered on GitHub.com, Pages, or a Pages site with a baseurl. It also has the advantage of making links in templates work the same way, so theme authors can use absolute URLs everywhere without having to use liquid filters. |
It shouldn't be doing that. To preserve the behavior on .com, it should look to resolve the link path relative to the file path, not relative to the published permalink URL. It should also be able to traverse to parent directories, as you describe. See https://github.com/benbalter/jekyll-relative-links/blob/master/spec/jekyll-relative-links/generator_spec.rb#L57-L64.
This plugin was designed to prevent that. You shouldn't be putting filters in your otherwise-vanilla markdown URLs, and in fact uses the What I think the issue might be is that this plugin currently only supports links to Markdown files, not images. Based on https://help.github.com/articles/about-readmes/#relative-links-and-image-paths-in-readme-files, it sounds like it needs to support images as well if we want feature parity. That leaves me with two questions:
|
I think that part works fine (well, after #13).
If #13 is merged, I think it solves it for markdown links and images. This implementation has the advantages of also working with My turn to ask questions:
|
@benbalter any thoughts on this? Images are broken on the Open Source Guides for any fork (e.g.) and I'd love to get this resolved. I'll start exploring other options if this isn't a viable option. |
@bkeepers I think this best route forward would be to:
I'm hesitant to go the HTML pipeline route, especially for something that's enabled by default.
I'll try to queue up time to tackle image support, but am glad to review a PR to add support (and get things bumped) if you are able to before I can. |
Closing based on feedback. Thanks. |
I'm struggling to come up with a way to make content for opensource.guide render on both GitHub and the pages site. Current solutions require using Jekyll filters (
![][{{ "url" | relative_url }}]
), which breaks rendering on GitHub (and breaks our pedantic markdown tests since that is not valid markdown).Here's a suggestion for an alternative approach: all "absolute" urls are assumed to be absolute to the site root, and are automatically corrected during rendering. This PR adds an HTML pipeline filter (largely borrowed from the filter used for rendering repository content on github.com) that makes urls for links and images relative to the base url.
<a href="/thing">link</a>
=><a href="/baseurl/thing">link</a>
<a href="thing">link</a>
=><a href="/baseurl/currentpage/thing">link</a>
<img src="/thing.png">
=><img src="/baseurl/thing.png">
These URLs are unaffected:
https://example.com/
//example.com/
#foobar
/baseurl/foo
You can see progress on getting this working here: github/opensource.guide#315.
If this works, I think would remove the need for
relative_url
andabsolute_url
filters.@benbalter @parkr - what do you think about this approach?
cc github/opensource.guide#307