1
0

wrong-filename.sh 1.3 KB

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: MIT
  3. # This script checks consistency between the filenames and the page title.
  4. # Usage: ./scripts/wrong-filename.sh
  5. # Output file for recording inconsistencies
  6. OUTPUT_FILE="inconsistent-filenames.txt"
  7. # Remove existing output file (if any)
  8. rm -f "$OUTPUT_FILE"
  9. touch "$OUTPUT_FILE"
  10. IGNORE_LIST=("exclamation mark" "caret" "dollar sign" "tilde" "history expansion" "qm move disk" "umount" "rename" "pacman f" "pacman r" "pacman s")
  11. set -e
  12. # Iterate through all Markdown files in the 'pages' directories
  13. find pages* -name '*.md' -type f | while read -r path; do
  14. # Extract the expected command name from the filename
  15. COMMAND_NAME_FILE=$(basename "$path" | head -c-4 | sed 's/nix3/nix/' | sed 's/\.fish//' | sed 's/\.js//' | sed 's/\.1//' | tr '-' ' ' | tr '[:upper:]' '[:lower:]')
  16. # Extract the command name from the first line of the Markdown file
  17. COMMAND_NAME_PAGE=$(head -n1 "$path" | tail -c+3 | sed 's/--//' | tr '-' ' ' | tr '[:upper:]' '[:lower:]')
  18. # Check if there is a mismatch between filename and content command names
  19. if [[ "$COMMAND_NAME_FILE" != "$COMMAND_NAME_PAGE" && ! ${IGNORE_LIST[*]} =~ $COMMAND_NAME_PAGE ]]; then
  20. echo "Inconsistency found in file: $path: $COMMAND_NAME_PAGE should be $COMMAND_NAME_FILE" >> "$OUTPUT_FILE"
  21. fi
  22. done