2024-02-08 09:01:27 +00:00
|
|
|
#!/bin/bash
|
|
|
|
cwd=`dirname "${0}"`
|
2024-02-08 11:06:40 +00:00
|
|
|
|
2024-02-08 10:14:51 +00:00
|
|
|
function rewritedate () {
|
|
|
|
echo "$1 : $2"
|
|
|
|
echo $2 | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$1"
|
|
|
|
}
|
2024-02-08 09:01:27 +00:00
|
|
|
FILES=$(find $cwd/content -name "*.md")
|
|
|
|
IFS=$'\n'
|
|
|
|
for f in $FILES
|
|
|
|
do
|
|
|
|
BDATE=$(stat -f "%SB" "$f");
|
2024-02-08 11:06:40 +00:00
|
|
|
DATE=$(LC_ALL=C date -j -f "%b %d %H:%M:%S %Y" "$BDATE" "+%FT%T%z");
|
2024-02-08 09:01:27 +00:00
|
|
|
FLINE=$(head -n 1 "$f");
|
2024-02-08 11:06:40 +00:00
|
|
|
|
|
|
|
LOCALDATE=$(LC_ALL=C date -j -f "%b %d %H:%M:%S %Y" "$BDATE" "+%s" );
|
|
|
|
GITDATERAW=$(git blame $f |tail -1| grep -Eo '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}');
|
|
|
|
GITDATE=$(LC_ALL=C date -j -f "%Y-%m-%d %H:%M:%S" "$GITDATERAW" "+%s");
|
|
|
|
GITDATE_2=$(LC_ALL=C date -j -f "%Y-%m-%d %H:%M:%S" "$GITDATERAW" "+%FT%T%z");
|
2024-02-08 10:14:51 +00:00
|
|
|
if [[ "$FLINE" == "---" ]];
|
|
|
|
then
|
2024-02-08 11:06:40 +00:00
|
|
|
ORIGINDATE_RAW=$(yq --front-matter=extract '.date' "$f")
|
|
|
|
ORIGINDATE=$(date -j -f "%FT%T%z" "$ORIGINDATE_RAW" "+%s")
|
|
|
|
|
2024-02-08 10:14:51 +00:00
|
|
|
if [ $LOCALDATE -lt $ORIGINDATE ]; then
|
|
|
|
echo "$f has frontmatter and date of local file is older. overwriting."
|
2024-02-08 11:06:40 +00:00
|
|
|
rewritedate $f $DATE
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $GITDATE -lt $LOCALDATE ]; then
|
|
|
|
echo "Oldest commit date is older than birth date. overwriting"
|
|
|
|
rewritedate $f $GITDATE_2
|
2024-02-08 09:01:27 +00:00
|
|
|
fi
|
|
|
|
else
|
2024-02-08 10:14:51 +00:00
|
|
|
echo "$f has no frontmatter, adding to it";
|
2024-02-08 09:01:27 +00:00
|
|
|
gsed -i '1i---\n---' "$f"
|
2024-02-08 10:14:51 +00:00
|
|
|
rewritedate $f $DATE
|
2024-02-08 09:01:27 +00:00
|
|
|
fi
|
|
|
|
done
|