From 2c22f85889a470e5435d7384f14ea1de6ec5093e Mon Sep 17 00:00:00 2001 From: SoundDrill31 <84176052+sounddrill31@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:16:17 +0530 Subject: [PATCH] Upload the correct sidebar script --- helper-scripts/gen-subxml.sh | 108 ++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 41 deletions(-) diff --git a/helper-scripts/gen-subxml.sh b/helper-scripts/gen-subxml.sh index 47a684a..91b4b79 100644 --- a/helper-scripts/gen-subxml.sh +++ b/helper-scripts/gen-subxml.sh @@ -1,47 +1,73 @@ #!/bin/bash -# Base directory +# Save the initial working directory +initial_pwd=$(pwd) + +# Navigate to the specified directory base_dir="NEP2020/2024" +cd "$base_dir" || { echo "Base directory not found"; exit 1; } + +# Initialize XML structure +xml_output="\n" +xml_output+="\n" # Start with a root element for the sidebar + +# Loop through each folder in the base directory +for folder in */; do + # Navigate into the folder + cd "$folder" || { echo "Directory $folder not found"; continue; } + + # Get the current folder name (e.g., BCA) + folder_name=$(basename "$PWD") + + # Add a program node + xml_output+=" \n" -# Loop through each folder in NEP/2024/ -for folder in "$base_dir"/*/; do - # Check if it's a directory - if [ -d "$folder" ]; then - echo "Processing folder: $folder" - - # Loop through each subfolder in the current folder - for subfolder in "$folder"/*/; do - # Check if it's a directory - if [ -d "$subfolder" ]; then - echo " Processing subfolder: $subfolder" - - # Change to the subfolder - cd "$subfolder" || continue - - # Run the specified commands - bash ../../../../helper-scripts/gen-assign.sh - bash ../../../../helper-scripts/gen-lab.sh - bash ../../../../helper-scripts/gen-solved.sh - - # Output lab.md - echo "Outputting lab.md" - # Assuming you want to create or modify lab.md here - # (Add your output command here if needed) - cat lab.md - - # Output assignment.md - echo "Outputting assignment.md" - # (Add your output command here if needed) - cat assignment.md - - # Output solved.md - echo "Outputting solved.md" - # (Add your output command here if needed) - cat solved.md - - # Return to the previous directory - cd - || exit + # Loop through semester folders + for sem_folder in [0-9]*sem; do + # Extract the semester number + sem_number=${sem_folder:0:1} # Get the first character (1, 2, 3, etc.) + + # Determine the year based on the semester number + year=$(( (sem_number + 1) / 2 )) # 1st and 2nd sem -> 1st year, 3rd and 4th sem -> 2nd year, etc. + + # Create a year node + xml_output+=" \n" + + # Add semester node + xml_output+=" \n" + + # Loop through each folder inside the semester folder + for subject_folder in "$sem_folder"/*; do + if [[ -d "$subject_folder" ]]; then # Check if it's a directory + # Check if index.md exists in the subject folder + if [[ -f "$subject_folder/index.md" ]]; then + # Read the first line of index.md + subject_name=$(head -n 1 "$subject_folder/index.md" | sed 's/^# //;s/\r//g') # Remove "# " and any carriage return + + # Add subject name as a sub-object + xml_output+=" $subject_name\n" + fi fi done - fi -done \ No newline at end of file + + # Close semester node + xml_output+=" \n" + + # Close year node + xml_output+=" \n" + done + + # Close program node + xml_output+=" \n" + + # Navigate back to the base directory + cd "$initial_pwd" || { echo "Failed to return to base directory"; exit 1; } +done + +# Close the main XML node +xml_output+="" + +# Save the XML output to sidebar.xml in the initial working directory +echo -e "$xml_output" > "$initial_pwd/sidebar.xml" + +echo "XML file sidebar.xml has been created successfully in $initial_pwd."