From 0d47beba97226fe1def97a2d3b385d466bdc104b Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 13 Jul 2020 11:20:07 +0800 Subject: [PATCH] Improved the tool scripts. - Avoid the empty lastmod file. - Check if there is no post. - Fixed the prompt message. --- _scripts/sh/create_pages.sh | 6 ++++++ _scripts/sh/dump_lastmod.sh | 9 ++++++++- tools/publish.sh | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/_scripts/sh/create_pages.sh b/_scripts/sh/create_pages.sh index 5e675fd..6e152d1 100755 --- a/_scripts/sh/create_pages.sh +++ b/_scripts/sh/create_pages.sh @@ -45,6 +45,7 @@ read_tags() { init() { + if [[ -d categories ]]; then rm -rf categories fi @@ -53,6 +54,10 @@ init() { rm -rf tags fi + if [[ ! -d _posts ]]; then + exit 0 + fi + mkdir categories tags } @@ -130,6 +135,7 @@ create_pages() { main() { + init for _file in $(ls "_posts") diff --git a/_scripts/sh/dump_lastmod.sh b/_scripts/sh/dump_lastmod.sh index ab45706..1190e60 100755 --- a/_scripts/sh/dump_lastmod.sh +++ b/_scripts/sh/dump_lastmod.sh @@ -19,6 +19,7 @@ OUTPUT_FILE=updates.yml _init() { + if [[ ! -d "$OUTPUT_DIR" ]]; then mkdir "$OUTPUT_DIR" fi @@ -27,7 +28,9 @@ _init() { rm -f "$OUTPUT_DIR/$OUTPUT_FILE" fi - touch "$OUTPUT_DIR/$OUTPUT_FILE" + if [[ ! -d $POST_DIR ]]; then + exit 0 + fi } @@ -55,6 +58,10 @@ _has_changed() { _dump() { local _lasmod="`git log -1 --pretty=%ad --date=iso $2`" + if [[ ! -f "$OUTPUT_DIR/$OUTPUT_FILE" ]]; then + touch "$OUTPUT_DIR/$OUTPUT_FILE" + fi + echo "-" >> "$OUTPUT_DIR/$OUTPUT_FILE" echo " filename: '$1'" >> "$OUTPUT_DIR/$OUTPUT_FILE" echo " lastmod: '$_lasmod'" >> "$OUTPUT_DIR/$OUTPUT_FILE" diff --git a/tools/publish.sh b/tools/publish.sh index 9378d61..4917d9f 100755 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -19,7 +19,7 @@ check_status() { local _change=$(git status . -s) if [[ ! -z ${_change} ]]; then - echo "Warning: Commit the changes of the changes first:" + echo "Warning: Commit the following changes first:" echo "$_change" exit 1 fi