-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ab0df8
commit 2c22f85
Showing
1 changed file
with
67 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
xml_output+="<sidebar>\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+=" <program name=\"$folder_name\">\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+=" <year number=\"$year\">\n" | ||
|
||
# Add semester node | ||
xml_output+=" <semester name=\"$sem_folder\">\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>$subject_name</subject>\n" | ||
fi | ||
fi | ||
done | ||
fi | ||
done | ||
|
||
# Close semester node | ||
xml_output+=" </semester>\n" | ||
|
||
# Close year node | ||
xml_output+=" </year>\n" | ||
done | ||
|
||
# Close program node | ||
xml_output+=" </program>\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+="</sidebar>" | ||
|
||
# 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." |