forked from godot-jp/godot-jp.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_post.sh
126 lines (109 loc) · 2.99 KB
/
new_post.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
WORK_DIR=`pwd`/content/reference/
sections_arr=()
function color(){
COLOR=33
case $1 in
red)
COLOR=31;;
green)
COLOR=32;;
blue)
COLOR=34;;
esac
local ESC=$(printf '\033') # \e や \x1b または $'\e' は使用しない
echo "${ESC}[${COLOR}m${2}${ESC}[m";
}
function new_post(){
echo どのカテゴリーで記事を作成しますか?
local n=1
for cats in "${sections_arr[@]}"; do
color green "[$n] $(basename ${cats})"
let n=$n+1
done
color red "[0] メニューに戻る"
read menu
if [ $menu = "0" ]; then select_mode; fi
clear
local cats_path=${sections_arr[menu-1]}
echo 「$(basename $cats_path)」に記事を作成します。
echo 記事の名前を入力してください(記事スラッグになります)
read post_name
clear
echo 以下の内容で記事を作成します。
echo -----------------------------
echo カテゴリー:$(basename $cats_path)
echo ファイルパス:$cats_path/$post_name/index.md
echo 記事名:$post_name
echo -----------------------------
echo よろしいですか?(y/n)
read confirm
if [ $confirm = "y" ]; then
hugo new $cats_path/$post_name/index.md
else
echo 作成しないキャンセル
select_mode
fi
}
function new_section(){
echo カテゴリー名を入力してください。
read cat_name
echo 以下の内容でカテゴリーを作成します。
echo パス:$WORK_DIR$cat_name/_index.md
echo よろしいですか?(y/n)
read confirm
if [ $confirm = "y" ]; then
hugo new $WORK_DIR$cat_name/_index.md
else
echo 作成しないキャンセル
select_mode
fi
}
function new_news(){
echo 以下の内容でニュース記事を作成します。
echo よろしいですか?(y/n)
today=`date "+%Y%m%d%H%M%S"`
echo パス:news/news-$today/index.md
read confirm
if [ $confirm = "y" ]; then
hugo new news/news-$today/index.md
else
echo 作成しないキャンセル
select_mode
fi
}
function select_mode(){
clear
for dir in `find $WORK_DIR* -maxdepth 0 -type d`;
do
sections_arr+=($dir)
done
#echo ${sections_arr[@]}
echo メニューを選んでください。
color green "[1] 記事を作成"
color green "[2] セクションを作成"
color green "[3] ニュース記事を作成"
color red "[0] 終了"
read menu
case $menu in
0)
exit ;;
1)
clear
echo 記事を作成します
new_post;;
2)
clear
echo セクションを作成します
new_section;;
3)
clear
echo ニュース記事を作成します
new_news;;
*)
echo 入力エラーです。
sleep 2
select_mode;;
esac
}
select_mode