Created
February 19, 2020 00:09
-
-
Save antoniosb/03d403e55ef90f2c1d4c316666bd51c3 to your computer and use it in GitHub Desktop.
Increment weights on front matter for Hugo content pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, it should be executed from the root of the Hugo repository. 😅