jekyll/jekyll-seo-tag

Support for image paths relative to post

numist opened this issue · 6 comments

My config uses permalink: /post/:year/:title/ together with jekyll-postfiles to keep assets local to their respective posts. This allows me to use simpler image tags in my Markdown (![…](image.jpg)) when editing and as a consequence my post's images tend to be shipped to https://:url/post/:year/:title/image.jpg.

Pre-#44, it was possible to specify image: image.jpg in the front matter and the generated URL would be relative to the post, but now jekyll-seo emits https://:url/image.jpg, which does not exist. #76 improved things somewhat by reintroducing the ability to link off-site images, but it's still not possible to use post-relative paths.

Obviously this can be worked around by specifying the fully expanded path (image: /post/2022/cool-title/image.jpg) in the front-matter, but this is brittle to reorganization (for example, when a post is moved from _drafts to _posts).

I think an ideal solution would allow domain-relative paths to be specified with a leading / (which is already consistent with the documentation) and post-relative paths to be specified without, but doing so would revert the behaviour described in #24 back to how it used to be—a second compatibility break.

So before investigating the code any further I wanted to know: what do people think about this?

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master/main branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

Alrighty, in the absence of opinions I'll draft a PR for this.

I just ran into this, and it sounds like you're planning three use cases for specifying a twitter image:

  1. From some other site, specified as https://example.com/project/post/path/to/image.png.
  2. Relative to this project's site, specified as /post/path/to/image.png.
  3. Relative to this post, specified as path/to/image.png.

I looked at the current code, and it seems to handle use cases 1 and 2 reasonably well. I guess you're going to add another conditional to handle case 3 when raw_path isn't absolute and doesn't start with /. Cases 1 and 3 will just use the raw_path as is, right?

For case 2, can I suggest that you switch to using filters.relative_url? With filters.absolute_url, I get http:// with the default GitHub Pages configuration. I haven't found any actual problems with http://, but it makes me nervous.

I get http:// with the default GitHub Pages configuration. I haven't found any actual problems with http://, but it makes me nervous.

To be clear, you mean absolute_url is giving you http:// but you want the URL to not include a scheme (or domain) so it will match the current page's (which presumably is https://)? That sounds like a separate issue but I'm happy to fold it in.

The opengraph spec is a bit ambiguous, but by the robustness principle my interpretation is that it's necessary to use absolute_url. Even if it's not, absolute_url is a liquid filter so it's probably worth taking up with the jekyll project if it's not giving you what you're expecting.

Fixed by #466