feat(pre-commit): sync config.toml and theme.toml [extra]

main
welpo 2 years ago
parent d3167adb8f
commit 1601fbf30c
No known key found for this signature in database
GPG Key ID: A2F978CF4EC1F5A6

@ -11,6 +11,7 @@
# Compresses PNG files with either oxipng or optipng if available. #
# Runs subset_font if config.toml has been modified. #
# Updates the README if the line numbers for the language section have changed. #
# Syncs the [extra] section from config.toml to theme.toml. #
# #
# Stops you from commiting: #
# - a draft .md file #
@ -131,6 +132,27 @@ for file in $all_changed_files; do
if [[ "$file" == *.min.js ]]; then
is_minified "$file"
fi
# Sync the [extra] section from config.toml to theme.toml.
# Check if config.toml has been modified; use spaces to avoid matching a substring.
if [[ "$file" == "config.toml" ]]; then
# Get the line number where [extra] starts in config.toml.
config_extra_line=$(grep -n "^\[extra\]$" "config.toml" | cut -d: -f1)
# Extract content after [extra] from config.toml.
config_extra_content=$(tail -n +"$config_extra_line" "config.toml")
# Get the line number where [extra] starts in theme.toml.
theme_extra_line=$(grep -n "^\[extra\]$" "theme.toml" | cut -d: -f1)
# Replace content after [extra] in theme.toml with extracted content from config.toml.
awk -v n="$theme_extra_line" 'NR<n' theme.toml > theme.tmp
echo "$config_extra_content" >> theme.tmp
mv theme.tmp theme.toml
# Add theme.toml to the list of files to be committed.
git add "theme.toml"
fi
done
# Get the modified .md to update the "updated" field in the front matter.

Loading…
Cancel
Save