benbalter / jekyll-relative-links

A Jekyll plugin to convert relative links to markdown files to their rendered equivalents
MIT License
141 stars 38 forks source link

jekyll-relative-links and Liquid's include_relative interact poorly #69

Open brycelelbach opened 3 years ago

brycelelbach commented 3 years ago

Describe the bug

If I have one page, a.md that has some relative links in it:

[X](./some/path/to/x.md)

And I use include_relative to include the content of b.md in another page:

{% include_relative a.md %}

In the generated a.html, the links will correctly point to x.html. But on b.html, the links will point to b.md.

brycelelbach commented 3 years ago

This seems to suggest the issue is that include_relative is processed after jekyll-relative-links. I believe that jekyll-relative-links uses a generator; Liquid stuff like include_relative is processed in the stage after generation (the render stage).

brycelelbach commented 3 years ago

I was able to work around this with a post_render hook:

Jekyll::Hooks.register :pages, :post_render do |doc|
  doc.output = doc.output.gsub(/(href="\.\/[^.]*)\.md"/, '\1.html"')
end

Maybe something similar and less hacky could be added to jekyll-relative-links? I'm afraid I don't know enough about Jekyll or Ruby to figure out how to make this less hacky.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

brycelelbach commented 3 years ago

Any update?