@@ -18,32 +18,28 @@ TYPE_TAG=1
1818category_count=0
1919tag_count=0
2020
21-
2221_read_yaml () {
2322 local _endline=" $( grep -n " \-\-\-" " $1 " | cut -d: -f 1 | sed -n ' 2p' ) "
2423 head -" $_endline " " $1 "
2524}
2625
27-
2826read_categories () {
2927 local _yaml=" $( _read_yaml " $1 " ) "
3028 local _categories=" $( echo " $_yaml " | grep " ^categories *:" ) "
3129 local _category=" $( echo " $_yaml " | grep " ^category *:" ) "
3230
33- if [[ ! -z " $_categories " ]]; then
31+ if [[ -n $_categories ]]; then
3432 echo " $_categories " | sed " s/categories *: *//;s/\[//;s/\].*//;s/, */,/g;s/\" //g;s/'//g"
35- elif [[ ! -z " _category" ]]; then
33+ elif [[ -n " _category" ]]; then
3634 echo " $_category " | sed " s/category *: *//;s/\[//;s/\].*//;s/, */,/g;s/\" //g;s/'//g"
3735 fi
3836}
3937
40-
4138read_tags () {
4239 local _yaml=" $( _read_yaml " $1 " ) "
4340 echo " $_yaml " | grep " ^tags *:" | sed " s/tags *: *//;s/\[//;s/\].*//;s/, */,/g;s/\" //g;s/'//g"
4441}
4542
46-
4743init () {
4844
4945 if [[ -d categories ]]; then
@@ -61,52 +57,49 @@ init() {
6157 mkdir categories tags
6258}
6359
64-
6560create_category () {
66- if [[ ! -z $1 ]]; then
61+ if [[ -n $1 ]]; then
6762 local _name=$1
6863 local _filepath=" categories/$( echo " $_name " | sed ' s/ /-/g' | awk ' {print tolower($0)}' ) .html"
6964
70- if [[ ! -f " $_filepath " ]]; then
65+ if [[ ! -f $_filepath ]]; then
7166 echo " ---" > " $_filepath "
7267 echo " layout: category" >> " $_filepath "
7368 echo " title: $_name " >> " $_filepath "
7469 echo " category: $_name " >> " $_filepath "
7570 echo " ---" >> " $_filepath "
7671
77- (( category_count= category_count+ 1 ))
72+ (( category_count = category_count + 1 ))
7873 fi
7974 fi
8075}
8176
82-
8377create_tag () {
84- if [[ ! -z $1 ]]; then
78+ if [[ -n $1 ]]; then
8579 local _name=$1
86- local _filepath=" tags/$( echo " $_name " | sed " s/ /-/g;s/'//g" | awk ' {print tolower($0)}' ) .html"
80+ local _filepath=" tags/$( echo " $_name " | sed " s/ /-/g;s/'//g" | awk ' {print tolower($0)}' ) .html"
8781
88- if [[ ! -f " $_filepath " ]]; then
82+ if [[ ! -f $_filepath ]]; then
8983
9084 echo " ---" > " $_filepath "
9185 echo " layout: tag" >> " $_filepath "
9286 echo " title: $_name " >> " $_filepath "
9387 echo " tag: $_name " >> " $_filepath "
9488 echo " ---" >> " $_filepath "
9589
96- (( tag_count= tag_count+ 1 ))
90+ (( tag_count = tag_count + 1 ))
9791 fi
9892 fi
9993}
10094
101-
10295# ########################################
10396# Create HTML pages for Categories/Tags.
10497# Arguments:
10598# $1 - an array string
10699# $2 - type specified option
107100# ########################################
108101create_pages () {
109- if [[ ! -z $1 ]]; then
102+ if [[ -n $1 ]]; then
110103 # split string to array
111104 IFS_BAK=$IFS
112105 IFS=' ,'
@@ -126,23 +119,20 @@ create_pages() {
126119 done
127120 ;;
128121
129- * )
130- ;;
122+ * ) ;;
131123
132- esac
124+ esac
133125
134- IFS=$IFS_BAK
126+ IFS=$IFS_BAK
135127 fi
136128
137129}
138130
139-
140131main () {
141132
142133 init
143134
144- for _file in $( find " _posts" -type f \( -iname \* .md -o -iname \* .markdown \) )
145- do
135+ for _file in $( find " _posts" -type f \( -iname \* .md -o -iname \* .markdown \) ) ; do
146136 local _categories=$( read_categories " $_file " )
147137 local _tags=$( read_tags " $_file " )
148138
0 commit comments