-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-posts-in-month-layout.sh
executable file
·60 lines (53 loc) · 1.62 KB
/
generate-posts-in-month-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
#!/bin/sh
# デフォルトの月を空に設定
month=""
# オプション解析
while [ "$1" != "" ]; do
case $1 in
--month )
shift
month=$1
;;
-h | --help )
echo "Usage: $0 --month 'YYYY-MM'"
exit
;;
* )
echo "Invalid option: $1"
echo "Usage: $0 --month 'YYYY-MM'"
exit 1
esac
shift
done
# 月が指定されていない場合のエラーメッセージ
if [ -z "$month" ]; then
echo "Error: --month parameter is required."
echo "Usage: $0 --month 'YYYY-MM'"
exit 1
fi
# 年と月を分割
year=$(echo "$month" | cut -d '-' -f 1)
month_only=$(echo "$month" | cut -d '-' -f 2)
# テンプレートの生成
cat <<EOL
---
title: "Posts in $month"
permalink: "/$year/$month_only"
layout: archive
author_profile: false
---
{% assign postsInYear = site.posts | where_exp: "item", "item.hidden != true" | group_by_exp: 'post', 'post.date | date: "%Y-%m"' %}
{% assign postsIn$year$month_only = postsInYear | where: 'name', '$month' %}
{% assign entries_layout = page.entries_layout | default: 'list' %}
{% for year in postsIn$year$month_only %}
<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>
<a href="#page-title" class="back-to-top">{{ site.data.ui-text[site.locale].back_to_top | default: 'Back to Top' }} ↑</a>
</section>
{% endfor %}
EOL