1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-22 10:22:08 +02:00
tldr/scripts/wrong-filename.sh
K.B.Dharun Krishna d8fb257277 wrong-filename.sh: update output filename
Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com>
2023-12-24 10:55:30 +05:30

26 lines
1,006 B
Bash
Executable file

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