Improved the tool scripts.

- Avoid the empty lastmod file.
- Check if there is no post.
- Fixed the prompt message.
This commit is contained in:
Cotes Chung 2020-07-13 11:20:07 +08:00
parent c0ba181246
commit 0d47beba97
3 changed files with 15 additions and 2 deletions

View file

@ -45,6 +45,7 @@ read_tags() {
init() { init() {
if [[ -d categories ]]; then if [[ -d categories ]]; then
rm -rf categories rm -rf categories
fi fi
@ -53,6 +54,10 @@ init() {
rm -rf tags rm -rf tags
fi fi
if [[ ! -d _posts ]]; then
exit 0
fi
mkdir categories tags mkdir categories tags
} }
@ -130,6 +135,7 @@ create_pages() {
main() { main() {
init init
for _file in $(ls "_posts") for _file in $(ls "_posts")

View file

@ -19,6 +19,7 @@ OUTPUT_FILE=updates.yml
_init() { _init() {
if [[ ! -d "$OUTPUT_DIR" ]]; then if [[ ! -d "$OUTPUT_DIR" ]]; then
mkdir "$OUTPUT_DIR" mkdir "$OUTPUT_DIR"
fi fi
@ -27,7 +28,9 @@ _init() {
rm -f "$OUTPUT_DIR/$OUTPUT_FILE" rm -f "$OUTPUT_DIR/$OUTPUT_FILE"
fi fi
touch "$OUTPUT_DIR/$OUTPUT_FILE" if [[ ! -d $POST_DIR ]]; then
exit 0
fi
} }
@ -55,6 +58,10 @@ _has_changed() {
_dump() { _dump() {
local _lasmod="`git log -1 --pretty=%ad --date=iso $2`" 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 "-" >> "$OUTPUT_DIR/$OUTPUT_FILE"
echo " filename: '$1'" >> "$OUTPUT_DIR/$OUTPUT_FILE" echo " filename: '$1'" >> "$OUTPUT_DIR/$OUTPUT_FILE"
echo " lastmod: '$_lasmod'" >> "$OUTPUT_DIR/$OUTPUT_FILE" echo " lastmod: '$_lasmod'" >> "$OUTPUT_DIR/$OUTPUT_FILE"

View file

@ -19,7 +19,7 @@ check_status() {
local _change=$(git status . -s) local _change=$(git status . -s)
if [[ ! -z ${_change} ]]; then if [[ ! -z ${_change} ]]; then
echo "Warning: Commit the changes of the changes first:" echo "Warning: Commit the following changes first:"
echo "$_change" echo "$_change"
exit 1 exit 1
fi fi