I've built a Jekyll blog that includes a post archive. I developed the archive using the jekyll-archives
plugin. I'm happy with the website and the archive pages are working fine. The problem is that archived posts are also shown on the current website, which is built with jekyll-paginate
.
I don't want archived posts to be shown on the current website because archived posts should be "archived" and only be accessible through the archive pages. Suppose I have posts from 2020 until 2022. I want 2021 and 2020 posts to be archived and appear on the archive pages only whilst the current paginated website lists 2022 posts only. How do I achieve this effect?
My jekyll-archives
configuration in _config.yml
file:
jekyll-archives:
enabled: all
layout: archive
permalinks:
year: '/blogs/archives/:year/'
title: 'Archived :year'
My archive template code:
<h1>Archive of posts from {{ page.date | date: "%Y" }}</h1>
<ul class="posts">
{% for post in page.posts %}
<li>
<span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
<a class="post-link" href="{{ post.url | relative_url }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
I found a workaround to the problem. To remove the archived posts from the current website ( /blogs/
), I first set the permalink
value to the directory in which I want to keep the archived posts. For instance, /blogs/archives/:year/:title/
. Then I ran the jekyll-archives
plugin to archive the markdown-based posts. All posts are saved in _posts
folder like a standard Jekyll blog. After that I copied all the generated HTML pages from the _site
folder to the site's archive directory as defined above, removed all the markdown source files of the archived posts from _posts
and set the permalink
value back to the current website /blogs/
. When I re-ran bundle exec jekyll serve
, the archived posts remain accessible at where they should be whilst being removed from the current website. If there's a more Jekyllist
(smarter) solution, I'd love to know!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.