wrong-filename.sh 1006 B

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  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. set -e
  10. # Iterate through all Markdown files in the 'pages' directories
  11. find pages* -name '*.md' -type f | while read -r path; do
  12. # Extract the expected command name from the filename
  13. COMMAND_NAME_FILE=$(basename "$path" | head -c-4 | tr '-' ' ' | tr '[:upper:]' '[:lower:]')
  14. # Extract the command name from the first line of the Markdown file
  15. COMMAND_NAME_PAGE=$(head -n1 "$path" | tail -c+3 | tr '-' ' ' | tr '[:upper:]' '[:lower:]')
  16. # Check if there is a mismatch between filename and content command names
  17. if [ "$COMMAND_NAME_FILE" != "$COMMAND_NAME_PAGE" ]; then
  18. echo "Inconsistency found in file: $path: $COMMAND_NAME_PAGE should be $COMMAND_NAME_FILE" >> "$OUTPUT_FILE"
  19. fi
  20. done