From 6410e8316754e69db3aba2f267944457de639699 Mon Sep 17 00:00:00 2001 From: Gllmar Date: Sun, 15 Sep 2024 13:09:26 -0400 Subject: [PATCH] =?UTF-8?q?+=20recursive=20subnav,=20remplace=20le=20tag?= =?UTF-8?q?=20au=20lieu=20de=20r=C3=A9ecrire=20le=20md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .run/20_generate_subnav.sh | 155 +++++++++++++++++------ activites/README.md | 3 +- contenus/1_presentation/README.md | 4 +- contenus/1_presentation/github/README.md | 3 +- contenus/2_scenarisation/README.md | 3 +- contenus/README.md | 24 +++- 6 files changed, 146 insertions(+), 46 deletions(-) diff --git a/.run/20_generate_subnav.sh b/.run/20_generate_subnav.sh index f0d14b6..72b202e 100644 --- a/.run/20_generate_subnav.sh +++ b/.run/20_generate_subnav.sh @@ -16,29 +16,32 @@ get_title_from_readme() { # Function to check if README.md contains the generateSubNav comment contains_generate_subnav_comment() { local readme_path="$1" - grep -q "" "$readme_path" + grep -q '' "$readme_path" } -# Function to generate README.md in subfolders -generate_readme_in_subfolders() { +# Function to generate the subnavigation content recursively +generate_subnav_content() { local parent_dir="$1" - local readme_path="$parent_dir/README.md" - - # Extract title from the current README.md - local title - title=$(get_title_from_readme "$readme_path") - if [[ -z "$title" ]]; then - title=$(basename "$parent_dir") - fi + local indent_level="$2" + local content_lines=() - # Start building the new README.md content - local new_content="# $title\n\n\n\n" + # Remove trailing slash from parent_dir if any + parent_dir="${parent_dir%/}" - # Iterate over subdirectories and add links to each + # Iterate over subdirectories for subdir in "$parent_dir"/*/; do if [[ -d "$subdir" ]]; then + # Remove trailing slash from subdir + subdir="${subdir%/}" + local base_dir base_dir=$(basename "$subdir") + + # Skip excluded directories + if [[ " ${EXCLUDED_DIRS[*]} " =~ " ${base_dir} " ]]; then + continue + fi + local subdir_readme="$subdir/README.md" local subdir_title @@ -50,36 +53,115 @@ generate_readme_in_subfolders() { subdir_title="$base_dir" fi - # Clean up paths to avoid double slashes - local clean_parent_dir="${parent_dir%/}" - local clean_base_dir="${base_dir%/}" - - # Combine paths and ensure no double slashes - local absolute_path="$clean_parent_dir/$clean_base_dir/" - absolute_path="/${absolute_path#"$ROOT_DIR/"}" # Remove root directory and ensure no leading // - - # Replace any instances of double slashes (except the leading slash) - absolute_path=$(echo "$absolute_path" | sed 's|//|/|g') + # Get relative path from ROOT_DIR + local relative_path="${subdir#$ROOT_DIR/}" # Remove ROOT_DIR and following slash + relative_path="${relative_path#/}" # Remove any leading slash + relative_path="${relative_path%/}" # Remove any trailing slash + + # Build the link + local link + if [[ -n "$relative_path" ]]; then + link="/${relative_path}/" + else + link="/" + fi - new_content+="* [$subdir_title]($absolute_path)\n" - echo "Generated link for $absolute_path with title '$subdir_title'" - else - echo "Skipped directory (no README.md): $subdir" + # Build the line with proper indentation + local indent="" + for ((i=0; i "$readme_path" + # Join the content lines with newlines + local content=$(printf "%s\n" "${content_lines[@]}") + echo "$content" +} + +# Function to update README.md with the new subnav content +update_readme_with_subnav() { + local readme_path="$1" + local subnav_content="$2" + local tmpfile=$(mktemp) + local in_section=0 + local start_tag_found=0 + local end_tag_found=0 + + while IFS= read -r line || [ -n "$line" ]; do + if [[ "$line" == *''* ]]; then + echo "$line" >> "$tmpfile" + in_section=1 + start_tag_found=1 + # Write the subnav content immediately after the start tag + echo "$subnav_content" >> "$tmpfile" + elif [[ "$line" == *''* ]]; then + echo "$line" >> "$tmpfile" + in_section=0 + end_tag_found=1 + elif [[ $in_section -eq 0 ]]; then + echo "$line" >> "$tmpfile" + fi + # If in_section is 1 (between tags), skip the line + done < "$readme_path" + + if [[ $start_tag_found -eq 1 && $end_tag_found -eq 0 ]]; then + # Add the end tag if it was missing + echo "" >> "$tmpfile" + fi + + if [[ $start_tag_found -eq 0 ]]; then + # Start tag not found; append the content at the end of tmpfile + { + echo -e "\n" + echo "$subnav_content" + echo "" + } >> "$tmpfile" + fi + + # Replace the original file with the updated content + mv "$tmpfile" "$readme_path" +} + +# Function to generate README.md in subfolders +generate_readme_in_subfolders() { + local parent_dir="$1" + local readme_path="$parent_dir/README.md" + + # Extract title from the current README.md + local title + title=$(get_title_from_readme "$readme_path") + if [[ -z "$title" ]]; then + title=$(basename "$parent_dir") + fi + + # Generate the subnav content + local subnav_content + subnav_content=$(generate_subnav_content "$parent_dir" 0) + + # Update the README.md with the new subnav content + update_readme_with_subnav "$readme_path" "$subnav_content" } # Function to walk through directories and generate the subnav content generate_subnav() { local dir_path="$1" + # Remove trailing slash from dir_path if any + dir_path="${dir_path%/}" + # Check for README.md in the current directory if [[ -f "$dir_path/README.md" ]]; then - # Check if README.md contains the generateSubNav comment and has subdirectories + # Check if README.md contains the generateSubNav comment if contains_generate_subnav_comment "$dir_path/README.md"; then generate_readme_in_subfolders "$dir_path" fi @@ -91,6 +173,9 @@ generate_subnav() { for subdir in "$dir_path"/*/; do # Ensure subdir is a directory if [[ -d "$subdir" ]]; then + # Remove trailing slash from subdir + subdir="${subdir%/}" + local base_dir base_dir=$(basename "$subdir") if [[ ! " ${EXCLUDED_DIRS[*]} " =~ " ${base_dir} " ]]; then @@ -100,9 +185,5 @@ generate_subnav() { done } -# Start from the current directory -for dir in */; do - if [[ -d "$dir" ]]; then - generate_subnav "$dir" - fi -done +# Start from the root directory +generate_subnav "$ROOT_DIR" diff --git a/activites/README.md b/activites/README.md index 2ca2b91..a94d072 100644 --- a/activites/README.md +++ b/activites/README.md @@ -1,8 +1,7 @@ # Activités - * [Sortie Mutek ](/activites/0_sortie_mutek/) * [Présenter l'œuvres multimédia](/activites/1_corpus_multimedia/) * [Scénariser l'interactivité](/activites/2_scenariser/) - + diff --git a/contenus/1_presentation/README.md b/contenus/1_presentation/README.md index 84f1350..c48cfdb 100644 --- a/contenus/1_presentation/README.md +++ b/contenus/1_presentation/README.md @@ -1,10 +1,12 @@ # Présenter - * [Docsify](/contenus/1_presentation/docsify/) * [GIT](/contenus/1_presentation/git/) * [Github](/contenus/1_presentation/github/) + * [Publication de Pages GitHub](/contenus/1_presentation/github/pages/) + * [Intégration Continue](/contenus/1_presentation/github/scriptCI/) * [Markdown](/contenus/1_presentation/markdown/) * [vscode.dev](/contenus/1_presentation/vscodeDev/) + diff --git a/contenus/1_presentation/github/README.md b/contenus/1_presentation/github/README.md index 1e7ae6e..8fbf0ba 100644 --- a/contenus/1_presentation/github/README.md +++ b/contenus/1_presentation/github/README.md @@ -1,7 +1,6 @@ # Github - * [Publication de Pages GitHub](/contenus/1_presentation/github/pages/) * [Intégration Continue](/contenus/1_presentation/github/scriptCI/) - + diff --git a/contenus/2_scenarisation/README.md b/contenus/2_scenarisation/README.md index 65672ce..2e7a0be 100644 --- a/contenus/2_scenarisation/README.md +++ b/contenus/2_scenarisation/README.md @@ -1,7 +1,6 @@ # Scénariser - * [Communiquer une idée](/contenus/2_scenarisation/00_ideation/) * [Scénario cinématographique](/contenus/2_scenarisation/10_scenario_cinema/) * [Scénario interactif](/contenus/2_scenarisation/11_scenario_interactif/) @@ -14,4 +13,4 @@ * [Technologies](/contenus/2_scenarisation/40_technologie/) * [Mermaid](/contenus/2_scenarisation/80_mermaid/) * [Draw.io](/contenus/2_scenarisation/81_drawio/) - + diff --git a/contenus/README.md b/contenus/README.md index a504ac7..a3ed92e 100644 --- a/contenus/README.md +++ b/contenus/README.md @@ -1,7 +1,27 @@ # Contenus - +test après - * [Présenter](/contenus/1_presentation/) + * [Docsify](/contenus/1_presentation/docsify/) + * [GIT](/contenus/1_presentation/git/) + * [Github](/contenus/1_presentation/github/) + * [Publication de Pages GitHub](/contenus/1_presentation/github/pages/) + * [Intégration Continue](/contenus/1_presentation/github/scriptCI/) + * [Markdown](/contenus/1_presentation/markdown/) + * [vscode.dev](/contenus/1_presentation/vscodeDev/) * [Scénariser](/contenus/2_scenarisation/) + * [Communiquer une idée](/contenus/2_scenarisation/00_ideation/) + * [Scénario cinématographique](/contenus/2_scenarisation/10_scenario_cinema/) + * [Scénario interactif](/contenus/2_scenarisation/11_scenario_interactif/) + * [Le narratif dans l'interactif](/contenus/2_scenarisation/12_scenario_narratif/) + * [Ambiances](/contenus/2_scenarisation/20_moodboard/) + * [Scénarimage](/contenus/2_scenarisation/30_scenarimage/) + * [Inventaire multimédia](/contenus/2_scenarisation/31_inventaire_multimedia/) + * [Arborescence](/contenus/2_scenarisation/32_arborescence/) + * [Nomenclature](/contenus/2_scenarisation/33_nomenclature/) + * [Technologies](/contenus/2_scenarisation/40_technologie/) + * [Mermaid](/contenus/2_scenarisation/80_mermaid/) + * [Draw.io](/contenus/2_scenarisation/81_drawio/) + +test avant