diff --git a/.githooks/pre-commit b/.githooks/pre-commit index a8cfce3..c6f08ad 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -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 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.