@@ -31,16 +31,16 @@ read_categories() {
3131 local _category=$( echo " $_yaml " | grep " ^category:" )
3232
3333 if [[ ! -z " $_categories " ]]; then
34- echo " $_categories " | sed " s/categories: *//;s/\[//;s/\]//;s/, */,/g;s/\" //g;s/'//g"
34+ echo " $_categories " | sed " s/categories: *//;s/\[//;s/\].* //;s/, */,/g;s/\" //g;s/'//g"
3535 elif [[ ! -z " _category" ]]; then
36- echo " $_category " | sed " s/category: *//;s/\[//;s/\]//;s/, */,/g;s/\" //g;s/'//g"
36+ echo " $_category " | sed " s/category: *//;s/\[//;s/\].* //;s/, */,/g;s/\" //g;s/'//g"
3737 fi
3838}
3939
4040
4141read_tags () {
4242 local _yaml=$( _read_yaml $1 )
43- echo " $_yaml " | grep " ^tags:" | sed " s/tags: *//;s/\[//;s/\]//;s/, */,/g;s/\" //g;s/'//g"
43+ echo " $_yaml " | grep " ^tags:" | sed " s/tags: *//;s/\[//;s/\].* //;s/, */,/g;s/\" //g;s/'//g"
4444}
4545
4646
@@ -63,34 +63,38 @@ init() {
6363
6464
6565create_category () {
66- local _name=$1
67- local _filepath=" categories/$( echo $_name | sed ' s/ /-/g' | awk ' {print tolower($0)}' ) .html"
68-
69- if [[ ! -f $_filepath ]]; then
70- echo " ---" > $_filepath
71- echo " layout: category" >> $_filepath
72- echo " title: $_name " >> $_filepath
73- echo " category: $_name " >> $_filepath
74- echo " ---" >> $_filepath
75-
76- (( category_count= category_count+ 1 ))
66+ if [[ ! -z $1 ]]; then
67+ local _name=$1
68+ local _filepath=" categories/$( echo $_name | sed ' s/ /-/g' | awk ' {print tolower($0)}' ) .html"
69+
70+ if [[ ! -f $_filepath ]]; then
71+ echo " ---" > $_filepath
72+ echo " layout: category" >> $_filepath
73+ echo " title: $_name " >> $_filepath
74+ echo " category: $_name " >> $_filepath
75+ echo " ---" >> $_filepath
76+
77+ (( category_count= category_count+ 1 ))
78+ fi
7779 fi
7880}
7981
8082
8183create_tag () {
82- local _name=$1
83- local _filepath=" tags/$( echo $_name | sed " s/ /-/g;s/'//g" | awk ' {print tolower($0)}' ) .html"
84+ if [[ ! -z $1 ]]; then
85+ local _name=$1
86+ local _filepath=" tags/$( echo $_name | sed " s/ /-/g;s/'//g" | awk ' {print tolower($0)}' ) .html"
8487
85- if [[ ! -f $_filepath ]]; then
88+ if [[ ! -f $_filepath ]]; then
8689
87- echo " ---" > $_filepath
88- echo " layout: tag" >> $_filepath
89- echo " title: $_name " >> $_filepath
90- echo " tag: $_name " >> $_filepath
91- echo " ---" >> $_filepath
90+ echo " ---" > $_filepath
91+ echo " layout: tag" >> $_filepath
92+ echo " title: $_name " >> $_filepath
93+ echo " tag: $_name " >> $_filepath
94+ echo " ---" >> $_filepath
9295
93- (( tag_count= tag_count+ 1 ))
96+ (( tag_count= tag_count+ 1 ))
97+ fi
9498 fi
9599}
96100
@@ -102,47 +106,45 @@ create_tag() {
102106# $2 - type specified option
103107# ########################################
104108create_pages () {
105- if [[ $1 == ' ' ]]; then
106- exit 0
107- fi
109+ if [[ ! -z $1 ]]; then
110+ # split string to array
111+ IFS_BAK=$IFS
112+ IFS=' ,'
113+ local _string=$1
108114
109- # split string to array
110- IFS_BAK=$IFS
111- IFS=' ,'
112- local _string=$1
115+ case $2 in
113116
114- case $2 in
117+ $TYPE_CATEGORY )
118+ for i in ${_string# ,} ; do
119+ create_category $i
120+ done
121+ ;;
115122
116- $TYPE_CATEGORY )
117- for i in ${_string# ,} ; do
118- create_category $i
119- done
120- ;;
123+ $TYPE_TAG )
124+ for i in ${_string# ,} ; do
125+ create_tag $i
126+ done
127+ ;;
121128
122- $TYPE_TAG )
123- for i in ${_string# ,} ; do
124- create_tag $i
125- done
126- ;;
129+ * )
130+ ;;
127131
128- * )
129- ;;
132+ esac
130133
131- esac
134+ IFS=$IFS_BAK
135+ fi
132136
133- IFS=$IFS_BAK
134- }
137+ }
135138
136139
137140main () {
138141
139142 init
140143
141- for _file in $( ls " _posts" )
144+ for _file in $( find " _posts" -type f \( -iname \* .md -o -iname \* .markdown \) )
142145 do
143- local _path=" _posts/$_file "
144- local _categories=$( read_categories " $_path " )
145- local _tags=$( read_tags " $_path " )
146+ local _categories=$( read_categories " $_file " )
147+ local _tags=$( read_tags " $_file " )
146148
147149 create_pages " $_categories " $TYPE_CATEGORY
148150 create_pages " $_tags " $TYPE_TAG
0 commit comments