Skip to content

Instantly share code, notes, and snippets.

@antoniosb
Created February 19, 2020 00:09
Show Gist options
  • Save antoniosb/03d403e55ef90f2c1d4c316666bd51c3 to your computer and use it in GitHub Desktop.
Save antoniosb/03d403e55ef90f2c1d4c316666bd51c3 to your computer and use it in GitHub Desktop.
Increment weights on front matter for Hugo content pages
#!/bin/bash
# USAGE:
# increment_weight.sh (with no params) will increment ALL pages with weight by 1.
# increment_weight.sh X (X is the param) will increment ALL pages with weight greather than X by 1.
MINIMUM_WEIGHT=$1
if [ -z $MINIMUM_WEIGHT ]; then
MINIMUM_WEIGHT=0
fi
for FILE in `find ./content -type f | grep .md`
do
CURRENT_WEIGHT=`grep -E 'weight:\ \d+' $FILE | cut -d" " -f2`
if [ -z $CURRENT_WEIGHT ]; then
echo "⚠️ $FILE não tem weight ⚠️"
continue
fi
if [ "$CURRENT_WEIGHT" -gt "$MINIMUM_WEIGHT" ]; then
echo "PESO $CURRENT_WEIGHT - ARQUIVO: $FILE"
perl -i -pe 's/weight: \K\d+/$&+1/e' $FILE
fi
done
@antoniosb
Copy link
Author

Oh, it should be executed from the root of the Hugo repository. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment