mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-18 12:31:22 +02:00
Lint frontmatter (#5218)
This commit is contained in:
committed by
GitHub
parent
4d7ecfbbf7
commit
770a4138b4
30
lint/encoding.sh
Executable file
30
lint/encoding.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
check_encoding() {
|
||||
file="$1"
|
||||
encoding=$(file -b --mime-encoding "$file")
|
||||
|
||||
# Check if the encoding is neither UTF-8 nor US-ASCII
|
||||
if [[ "$encoding" != "utf-8" && "$encoding" != "us-ascii" ]]; then
|
||||
# Print the file path and encoding
|
||||
echo "Error: $file has encoding $encoding, which is not utf-8 or us-ascii"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check for UTF-8 BOM
|
||||
if [[ "$encoding" == "utf-8" ]]; then
|
||||
if head -c 3 "$file" | cmp -s <(echo -ne '\xEF\xBB\xBF'); then
|
||||
echo "Error: $file contains a UTF-8 BOM"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
export -f check_encoding
|
||||
|
||||
# Default to current directory if no argument is given
|
||||
directory="${1:-.}"
|
||||
|
||||
find "$directory" -type f -name "*.md" -print0 | xargs -0 -P 8 -I {} bash -c 'check_encoding "$@"' _ {}
|
Reference in New Issue
Block a user