2023-12-14 12:11:19 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2023-12-21 14:17:18 +00:00
|
|
|
# This script checks consistency between the filenames and the page title.
|
|
|
|
# Usage: ./scripts/wrong-filename.sh
|
|
|
|
|
|
|
|
# Output file for recording inconsistencies
|
|
|
|
OUTPUT_FILE="filename-consistency-check-output.txt"
|
|
|
|
# Remove existing output file (if any)
|
|
|
|
rm -f "$OUTPUT_FILE"
|
|
|
|
|
2023-12-14 12:11:19 +00:00
|
|
|
set -e
|
|
|
|
|
2023-12-21 14:17:18 +00:00
|
|
|
# Iterate through all Markdown files in the 'pages' directories
|
|
|
|
for path in $(find pages* -name '*.md' -type f); do
|
|
|
|
# Extract the expected command name from the filename
|
2023-12-14 12:11:19 +00:00
|
|
|
COMMAND_NAME_FILE=$(basename "$path" | head -c-4 | tr '-' ' ' | tr '[:upper:]' '[:lower:]')
|
2023-12-21 14:17:18 +00:00
|
|
|
|
|
|
|
# Extract the command name from the first line of the Markdown file
|
2023-12-14 12:11:19 +00:00
|
|
|
COMMAND_NAME_PAGE=$(head -n1 "$path" | tail -c+3 | tr '-' ' ' | tr '[:upper:]' '[:lower:]')
|
2023-12-21 14:17:18 +00:00
|
|
|
|
|
|
|
# Check if there is a mismatch between filename and content command names
|
2023-12-14 12:11:19 +00:00
|
|
|
if [ "$COMMAND_NAME_FILE" != "$COMMAND_NAME_PAGE" ]; then
|
2023-12-21 14:17:18 +00:00
|
|
|
echo "Inconsistency found in file: $path: $COMMAND_NAME_PAGE should be $COMMAND_NAME_FILE" >> "$OUTPUT_FILE"
|
2023-12-14 12:11:19 +00:00
|
|
|
fi
|
|
|
|
done
|