From 4164b91eecbe35544fcc7e06329c3f66e528dc21 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 16 Oct 2023 18:27:07 +0300 Subject: (s0) Reworked timestamps generation to work better --- csg | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/csg b/csg index fe6a6f8..ac41dc8 100755 --- a/csg +++ b/csg @@ -5,25 +5,35 @@ SOURCE="$2" OUTPUT="$(realpath "$3")" TITLEF="$4" -TIMESTAMPS="timestamps.txt" - -# $1 - file path -# $2 - stat file -# Line is in the format: name¶created¶edited -gitStats() { - local dates=($(git log --follow --pretty=format:%ad --date="format:%d %B %Y" -- $1)) - local line="./website${file:5:-2}html¶${dates[@]: -3:3}¶${dates[@]:0:3}" - echo -e $line >> $2 +TIMESTAMPS="$(realpath ./timestamps.txt)" + +### Helper functions + +isCommand() { + command -v "$1" &> /dev/null } -headc=$(git rev-parse HEAD) -update_timestamps="" -if [ ! -f "$TIMESTAMPS" ] || [ "$headc" != "$(head -1 "$TIMESTAMPS")" ]; then - update_timestamps="1" - echo "$headc" > "$TIMESTAMPS" +overwriteLine() { ### Stage 0 ### Create timestamps.txt file, if necessary +if isCommand 'git' +then + timestamps_writeDates() { + for file in $(find . -type f -name '*.md') + do + dates=($(git log --follow --pretty=format:%ad --date="format:%d %B %Y" -- "$file")) + line="$OUTPUT${file:1:-2}html\t${dates[@]: -3:3}\t${dates[@]:0:3}" + echo -e $line >> "$TIMESTAMPS" + done + } + + headc=$(git rev-parse HEAD) + if [ ! -f "$TIMESTAMPS" ] || [ "$headc" != "$(head -1 "$TIMESTAMPS")" ] + then + echo "$headc" > "$TIMESTAMPS" + (cd "$SOURCE" && timestamps_writeDates) + fi fi # Copy from SOURCE to OUTPUT -- cgit v1.3.1-23-gd82d