Mise à jour du 29 octobre 2025 à 15:05

This commit is contained in:
Toine 2025-10-29 15:05:48 +01:00
parent 4d8af39678
commit 0c334ab653
50 changed files with 262 additions and 1503 deletions

View file

@ -28,37 +28,30 @@ echo "Regroupement dans : $TARGET_DIR"
echo "Sortie → $OUTPUT_PATH"
echo "--------------------------------------------------"
# === BOUCLE SANS PIPE (clé du succès) ===
while IFS= read -r -d '' file; do
[[ "$file" == "$OUTPUT_PATH" ]] && continue
rel_path="${file#$TARGET_DIR/}"
echo "Traitement : $rel_path"
# --- Titre depuis # Premier ---
title_line=$(grep -m 1 "^[[:space:]]*#[[:space:]]*" "$file")
if [[ -n "$title_line" ]]; then
title=$(echo "$title_line" | sed 's/^[[:space:]]*#[[:space:]]*\(.*\)/\1/' | xargs)
content_start=2
# Ignorer si aucun contenu après le titre (que des blancs ou rien)
if ! tail -n +"$content_start" "$file" | grep -q '[^[:space:]]'; then
echo "Ignoré (titre sans contenu) : $rel_path"
continue
fi
else
# --- Sinon : nom du fichier ---
title=$(basename "$file" .md)
title=$(echo "$title" | sed 's/[-_]/ /g')
# Majuscule première lettre (macOS compatible)
title="$(echo "$title" | awk '{print toupper(substr($0,1,1)) substr($0,2)}')"
content_start=1
fi
# --- Ajout au fichier ---
printf "\n# %s\n\n" "$title" >> "$OUTPUT_PATH"
tail -n +"$content_start" "$file" >> "$OUTPUT_PATH"
printf "\n" >> "$OUTPUT_PATH"
done < <(find "$TARGET_DIR" -type f -name "*.md" ! -name "$OUTPUT" -not -empty -print0 | sort -z)
# === BOUCLE SUR SOUS-DOSSIERS (tri alphabétique) ===
while IFS= read -r -d '' subdir; do
rel_subdir="${subdir#$TARGET_DIR/}"
chapter_title=$(basename "$subdir")
chapter_title=$(echo "$chapter_title" | sed 's/[-_]/ /g')
# Majuscule première lettre (macOS compatible)
chapter_title="$(echo "$chapter_title" | awk '{print toupper(substr($0,1,1)) substr($0,2)}')"
echo "Chapitre : $chapter_title ($rel_subdir)"
printf "\n# %s\n\n" "$chapter_title" >> "$OUTPUT_PATH"
# === BOUCLE SUR FICHIERS .MD DU SOUS-DOSSIER ===
while IFS= read -r -d '' file; do
[[ "$file" == "$OUTPUT_PATH" ]] && continue
rel_file="${file#$subdir/}"
echo " → Traitement : $rel_file"
# Ajout du contenu entier du fichier (sans titre individuel)
cat "$file" >> "$OUTPUT_PATH"
printf "\n" >> "$OUTPUT_PATH" # Séparateur simple entre fichiers
done < <(find "$subdir" -maxdepth 1 -type f -name "*.md" ! -name "$OUTPUT" -not -empty -print0 | sort -z)
printf "\n---\n\n" >> "$OUTPUT_PATH" # Séparateur entre chapitres (optionnel, ligne horizontale)
done < <(find "$TARGET_DIR" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
echo "--------------------------------------------------"
echo "TERMINE : $OUTPUT_PATH"