Amélioration de la liste des fichiers MD
This commit is contained in:
@@ -6,23 +6,46 @@ README="FILES.md"
|
||||
TEMP_FILE=$(mktemp)
|
||||
|
||||
# Get all .md files in the repository except the README.md
|
||||
find . -type f -name "*.md" ! -name "README.md" | sort > "$TEMP_FILE"
|
||||
find . -type f -name "*.md" ! -name "$README" | sort > "$TEMP_FILE"
|
||||
|
||||
# Extract the list of .md files from README.md
|
||||
grep -o '\[.*\](.*\.md)' "$README" | sed 's/^.*(\(.*\))$/\1/' | sort > "${README}.old"
|
||||
# Function to get the title from a Markdown file
|
||||
get_title() {
|
||||
local file="$1"
|
||||
grep -m 1 '^# ' "$file" | sed 's/^# //'
|
||||
}
|
||||
|
||||
# Compare and update README.md
|
||||
comm -23 "${README}.old" "$TEMP_FILE" | while read -r file; do
|
||||
echo "Removing $file from $README"
|
||||
sed -i "\|$file|d" "$README"
|
||||
done
|
||||
# Start with a clean README.md
|
||||
echo "# Liste des fichiers Markdown" > "$README"
|
||||
|
||||
comm -13 "${README}.old" "$TEMP_FILE" | while read -r file; do
|
||||
echo "Adding $file to $README"
|
||||
echo "- [$file]($file)" >> "$README"
|
||||
done
|
||||
# Initialize variable to track the last directory
|
||||
last_directory=""
|
||||
|
||||
# Read the list of files and append to README.md
|
||||
while read -r file; do
|
||||
title=$(get_title "$file")
|
||||
# Convert file path to hierarchical levels
|
||||
IFS='/' read -r -a path_parts <<< "$file"
|
||||
indent=""
|
||||
for ((i=1; i<${#path_parts[@]}-1; i++)); do
|
||||
indent="$indent "
|
||||
done
|
||||
# Determine the current directory name
|
||||
if [ ${#path_parts[@]} -gt 2 ]; then
|
||||
level="${path_parts[-2]}"
|
||||
capitalized_level=$(echo "$level" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')
|
||||
|
||||
# Only add the directory name if it's different from the last one
|
||||
if [ "$last_directory" != "$capitalized_level" ]; then
|
||||
echo "$indent- **${capitalized_level}**" >> "$README"
|
||||
last_directory="$capitalized_level"
|
||||
fi
|
||||
echo "$indent - [$title]($file)" >> "$README"
|
||||
else
|
||||
echo "- [$title]($file)" >> "$README"
|
||||
fi
|
||||
done < "$TEMP_FILE"
|
||||
|
||||
# Clean up
|
||||
rm "$TEMP_FILE" "${README}.old"
|
||||
rm "$TEMP_FILE"
|
||||
|
||||
echo "$README has been updated."
|
||||
|
||||
Reference in New Issue
Block a user