Improved script tools.

- Allows posts to be placed in subdirectories (#41, #87).
- Identify posts file with the suffix ‘.markdown’.

**Page creator**
- Pass the posts without any categories or tags.
- Omit the YAML comments for categories/tags.

**Lastmod**
- compatible with one-digit month or day post files.
This commit is contained in:
Cotes Chung 2020-07-14 20:55:43 +08:00
parent 733bb0fbfa
commit 5b0aaa5403
2 changed files with 59 additions and 59 deletions

View file

@ -31,16 +31,16 @@ read_categories() {
local _category=$(echo "$_yaml" | grep "^category:") local _category=$(echo "$_yaml" | grep "^category:")
if [[ ! -z "$_categories" ]]; then if [[ ! -z "$_categories" ]]; then
echo "$_categories" | sed "s/categories: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g" echo "$_categories" | sed "s/categories: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
elif [[ ! -z "_category" ]]; then elif [[ ! -z "_category" ]]; then
echo "$_category" | sed "s/category: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g" echo "$_category" | sed "s/category: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
fi fi
} }
read_tags() { read_tags() {
local _yaml=$(_read_yaml $1) local _yaml=$(_read_yaml $1)
echo "$_yaml" | grep "^tags:" | sed "s/tags: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g" echo "$_yaml" | grep "^tags:" | sed "s/tags: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
} }
@ -63,6 +63,7 @@ init() {
create_category() { create_category() {
if [[ ! -z $1 ]]; then
local _name=$1 local _name=$1
local _filepath="categories/$(echo $_name | sed 's/ /-/g' | awk '{print tolower($0)}').html" local _filepath="categories/$(echo $_name | sed 's/ /-/g' | awk '{print tolower($0)}').html"
@ -75,10 +76,12 @@ create_category() {
((category_count=category_count+1)) ((category_count=category_count+1))
fi fi
fi
} }
create_tag() { create_tag() {
if [[ ! -z $1 ]]; then
local _name=$1 local _name=$1
local _filepath="tags/$( echo $_name | sed "s/ /-/g;s/'//g" | awk '{print tolower($0)}' ).html" local _filepath="tags/$( echo $_name | sed "s/ /-/g;s/'//g" | awk '{print tolower($0)}' ).html"
@ -92,6 +95,7 @@ create_tag() {
((tag_count=tag_count+1)) ((tag_count=tag_count+1))
fi fi
fi
} }
@ -102,10 +106,7 @@ create_tag() {
# $2 - type specified option # $2 - type specified option
######################################### #########################################
create_pages() { create_pages() {
if [[ $1 == '' ]]; then if [[ ! -z $1 ]]; then
exit 0
fi
# split string to array # split string to array
IFS_BAK=$IFS IFS_BAK=$IFS
IFS=',' IFS=','
@ -131,6 +132,8 @@ create_pages() {
esac esac
IFS=$IFS_BAK IFS=$IFS_BAK
fi
} }
@ -138,11 +141,10 @@ main() {
init init
for _file in $(ls "_posts") for _file in $(find "_posts" -type f \( -iname \*.md -o -iname \*.markdown \))
do do
local _path="_posts/$_file" local _categories=$(read_categories "$_file")
local _categories=$(read_categories "$_path") local _tags=$(read_tags "$_file")
local _tags=$(read_tags "$_path")
create_pages "$_categories" $TYPE_CATEGORY create_pages "$_categories" $TYPE_CATEGORY
create_pages "$_tags" $TYPE_TAG create_pages "$_tags" $TYPE_TAG

View file

@ -74,14 +74,12 @@ main() {
local _count=0 local _count=0
for _file in $(ls -r "$POST_DIR") for _file in $(find ${POST_DIR} -type f \( -iname \*.md -o -iname \*.markdown \))
do do
_filepath="$POST_DIR/$_file" _filename=$(basename $_file | sed 's/[0-9]\([0-9]*-\)//g;s/\..*//' ) # remove date and extension
_filename="${_file%.*}" # jekyll cannot read the extension of a file, so omit it.
_filename=${_filename:11} # remove the date
if _has_changed "$_filepath"; then if _has_changed "$_file"; then
_dump "$_filename" "$_filepath" _dump "$_filename" "$_file"
((_count=_count+1)) ((_count=_count+1))
fi fi