Using jekyll-archives to create category/tag pages.

This commit is contained in:
Cotes Chung 2020-11-18 23:16:09 +08:00
parent aac29d43e5
commit 1889b6b4e0
4 changed files with 17 additions and 7 deletions

View file

@ -7,6 +7,7 @@ group :jekyll_plugins do
gem "jekyll-paginate" gem "jekyll-paginate"
gem "jekyll-redirect-from" gem "jekyll-redirect-from"
gem "jekyll-seo-tag", "~> 2.6.1" gem "jekyll-seo-tag", "~> 2.6.1"
gem "jekyll-archives"
end end
group :test do group :test do

View file

@ -161,7 +161,6 @@ defaults:
label: Home label: Home
url: / url: /
sass: sass:
sass_dir: /assets/css sass_dir: /assets/css
style: compressed style: compressed
@ -198,3 +197,13 @@ sitemap_exclude: # Sitemap will exclude the following items.
- sitemap.xml - sitemap.xml
- robots.txt - robots.txt
- redirects.json - redirects.json
# see: <https://github.com/jekyll/jekyll-archives/blob/master/docs/configuration.md>
jekyll-archives:
enabled: [categories, tags]
layouts:
category: category
tag: tag
permalinks:
tag: '/tags/:name/'
category: '/categories/:name/'

View file

@ -10,11 +10,11 @@ layout: page
<h1 class="pl-lg-2"> <h1 class="pl-lg-2">
<i class="far fa-folder-open fa-fw text-muted"></i> <i class="far fa-folder-open fa-fw text-muted"></i>
{{ page.title }} {{ page.title }}
<span class="lead text-muted pl-2">{{ site.categories[page.category] | size }}</span> <span class="lead text-muted pl-2">{{ page.posts | size }}</span>
</h1> </h1>
<ul class="post-content pl-0"> <ul class="post-content pl-0">
{% for post in site.categories[page.category] %} {% for post in page.posts %}
<li class="d-flex justify-content-between pl-md-3 pr-md-3"> <li class="d-flex justify-content-between pl-md-3 pr-md-3">
<a href="{{ post.url | relative_url }}">{{ post.title }}</a> <a href="{{ post.url | relative_url }}">{{ post.title }}</a>
<span class="dash flex-grow-1"></span> <span class="dash flex-grow-1"></span>

View file

@ -11,10 +11,10 @@ layout: page
<h1 class="pl-lg-2"> <h1 class="pl-lg-2">
<i class="fa fa-tag fa-fw text-muted"></i> <i class="fa fa-tag fa-fw text-muted"></i>
{{ page.title }} {{ page.title }}
<span class="lead text-muted pl-2">{{ site.tags[page.tag] | size }}</span> <span class="lead text-muted pl-2">{{ page.posts | size }}</span>
</h1> </h1>
<ul class="post-content pl-0"> <ul class="post-content pl-0">
{% for post in site.tags[page.tag] %} {% for post in page.posts %}
<li class="d-flex justify-content-between pl-md-3 pr-md-3"> <li class="d-flex justify-content-between pl-md-3 pr-md-3">
<a href="{{ post.url | relative_url }}">{{ post.title }}</a> <a href="{{ post.url | relative_url }}">{{ post.title }}</a>
<span class="dash flex-grow-1"></span> <span class="dash flex-grow-1"></span>