-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-posts-in-year-layout.sh
executable file
·68 lines (62 loc) · 1.85 KB
/
generate-posts-in-year-layout.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
# デフォルトの年を空に設定
year=""
# オプション解析
while [ "$1" != "" ]; do
case $1 in
year=* )
year="${1#*=}"
;;
-h | --help )
echo "Usage: $0 year=YYYY"
exit
;;
* )
echo "Invalid option: $1"
echo "Usage: $0 year=YYYY"
exit 1
esac
shift
done
# 年が指定されていない場合のエラーメッセージ
if [ -z "$year" ]; then
echo "Error: year parameter is required."
echo "Usage: $0 year=YYYY"
exit 1
fi
# テンプレートの生成
cat <<EOL
---
title: "Posts in $year"
permalink: /$year/
layout: archive
author_profile: false
---
<ul class="taxonomy__index">
{% assign postsByYearMonth = site.posts | where_exp: "item", "item.hidden != true" | group_by_exp: 'post', 'post.date | date: "%Y-%m"' %}
{% assign postsIn$year = postsByYearMonth | where: 'name', '$year' %}
{% for year in postsByYearMonth %}
<li>
<a href="#{{ year.name }}">
<strong>{{ year.name }}</strong> <span class="taxonomy__count">{{ year.items | size }}</span>
</a>
</li>
{% endfor %}
</ul>
{% assign entries_layout = page.entries_layout | default: 'list' %}
<!-- {% assign postsIn$year = postsInYear | where: 'name', '$year' %} -->
{% for year in postsByYearMonth %}
<section id="{{ year.name }}" class="taxonomy__section">
<h2 class="archive__subtitle">{{ year.name }}</h2>
<div class="entries-{{ entries_layout }}">
{% for post in year.items %}
{% include archive-single.html type=entries_layout %}
{% endfor %}
</div>
<div class="back-to-top-container">
<a href="#page-title" class="back-to-top">BACK TO TOP ↑</a>
<a href="#{{ year.name }}" class="back-to-top">BACK TO {{ year.name }} ↑</a>
</div>
</section>
{% endfor %}
EOL