Skip to content

Commit 1c849bd

Browse files
committed
Fixed page creator script tool(issues cotes2020#47).
1 parent bf3e6b9 commit 1c849bd

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

_scripts/sh/create_pages.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,29 @@ TYPE_TAG=1
1818
category_count=0
1919
tag_count=0
2020

21+
22+
_read_yaml() {
23+
local _endline=$(grep -n "\-\-\-" $1 | cut -d: -f 1 | sed -n '2p')
24+
head -$_endline $1
25+
}
26+
27+
2128
read_categories() {
22-
if [[ $(grep "categories:" $1) ]]; then
23-
grep "categories:" $1 | head -1 | sed 's/categories: *//;s/\[//;s/\]//;s/, */,/g;s/"//g'
24-
elif [[ $(grep "category:" $1) ]]; then
25-
grep "category:" $1 | head -1 | sed 's/category: *//;s/\[//;s/\]//;s/, */,/g;s/"//g'
29+
local _yaml=$(_read_yaml $1)
30+
local _categories=$(echo "$_yaml" | grep "^categories:")
31+
local _category=$(echo "$_yaml" | grep "^category:")
32+
33+
if [[ ! -z "$_categories" ]]; then
34+
echo "$_categories" | sed "s/categories: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g"
35+
elif [[ ! -z "_category" ]]; then
36+
echo "$_category" | sed "s/category: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g"
2637
fi
2738
}
2839

2940

3041
read_tags() {
31-
grep "tags:" $1 | head -1 | sed 's/tags: *//;s/\[//;s/\]//;s/, */,/g;s/"//g'
42+
local _yaml=$(_read_yaml $1)
43+
echo "$_yaml" | grep "^tags:" | sed "s/tags: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g"
3244
}
3345

3446

0 commit comments

Comments
 (0)