jekyll / jekyll-seo-tag

A Jekyll plugin to add metadata tags for search engines and social networks to better index and display your site's content.
https://jekyll.github.io/jekyll-seo-tag
MIT License
1.66k stars 294 forks source link

Make .html ending optional in canonical URL #470

Closed thomaswitt closed 1 year ago

thomaswitt commented 2 years ago

I'd propose to make the .html ending in the default canonical URL optional.

There's an example for a patch:

https://blog.taragana.com/how-to-modify-jekyll-seo-tag-plugin-to-remove-html-from-canonical-url-and-ogurl-15902

jekyllbot commented 1 year ago

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.

FranseFrikandel commented 1 year ago

It appears Jekyll-SEO respects the permalink structure as set in the frontmatter. In my site I have set the following in the frontmatter defaults for the paths where my HTML files reside:

    scope:
      path: ""
    values:
      layout: "default"
      permalink: :path/:basename

This removes all file extensions for those paths when a frontmatter is defined. It also makes sure things like page.url are set correctly, so all your links on your website will immediatly redirect to the URL without the HTML, instead of having to redirect users.

Relevant documentation: https://jekyllrb.com/docs/permalinks/

EDIT: Just to clarify, what I'm saying is setting the permalink structure correctly in jekyll itself appears to resolve this issue, and should be done anyway for other reasons. I think this issue can be closed based on this.

thomaswitt commented 1 year ago

@FranseFrikandel – Thanks for the idea. That doesn't seem to be without side effects. I get the following error message when using your defaults:

Liquid Exception: The URL template doesn't have basename keys. Check your permalink template! raise NoMethodError, ^^^^^ in website/_layouts/post.html from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/url.rb:96:ingsub' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/url.rb:96:in generate_url_from_drop' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/url.rb:62:ingenerate_url' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/url.rb:46:in generated_permalink' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/url.rb:39:into_s' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/document.rb:247:in url' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/drops/drop.rb:65:inblock in delegate_method' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/drops/drop.rb:128:in public_send' from /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jekyll-4.2.2/lib/jekyll/drops/drop.rb:128:in[]'`

FranseFrikandel commented 1 year ago

The website I did this on didn't actually have any blog posts and was only static pages. It indeed breaks once you add a blog post.

The Jekyll documentation actually says setting the URL structure for pages in frontmatter defaults doesnt work... But it appears to be working fine for me. Limiting the front matter scope to be just pages by adding type: pages to the scope appears to fix your issue. You would have to add another default for posts where you use :title instead of :basename and it should work everywhere.

thomaswitt commented 1 year ago

Sounds like a potential solution. I'll look into it. Thanks for your ideas, @FranseFrikandel.