jekyll-archives icon indicating copy to clipboard operation
jekyll-archives copied to clipboard

Automatically add .html to generated archives names without extension

Open Exagone313 opened this issue 8 years ago • 2 comments

Hi,

If you use an archive permalink that is not a directory and not ending by .html, such as /:year, it generates a file without extension, instead of adding .html (unlike with Jekyll's post permalink).

I'd like to add the html extension without having page.url containing it (would be the case if you use /:year.html).

Note that I actually use the v2.1.1 tagged version.

Exagone313 avatar Jul 23 '17 23:07 Exagone313

This is exactly what we need and would add parity with how Jekyll's own permalinks work.

For example in Jekyll:

collections:
  posts:
    permalink: /posts/:year/:month/:day/:title

will produce files at /posts/2020/06/11/mypost.html and permalink (page.url) of /posts/2020/06/11/mypost

The latter is how we want to serve them (and how they should appear in canonical links and sitemaps etc, which use the page.url variable)

However in Jekyll-archives:

jekyll-archives:
  permalinks:
    year: '/posts/:year'

will produce the correct permalink but output the wrong file (without .html extension)

and

jekyll-archives:
  permalinks:
    year: '/posts/:year.html'

will output to the right file but have the wrong permalink.

davidc avatar Jun 11 '20 19:06 davidc

A partial workaround is to strip .html when printing links to archives, but you can't fix it for plugins reading the permalink (such as for jekyll-sitemap).

{%- assign year_archives = site.archives | where:"type", "year" -%}
{%- for archive in year_archives reversed %}
<p class="center"><a href="{{ archive.url | replace: '.html', '' }}">{{ archive.date | date: "%Y" }}</a></p>
{%- endfor %}

Exagone313 avatar Jun 12 '20 15:06 Exagone313