@@ -45,7 +45,6 @@ clone_repo() {
4545 rm -rf temp/
4646}
4747
48-
4948# Function to replace patterns in .qmd files
5049replace_in_qmd_files () {
5150 local folder_path=" $1 "
@@ -65,9 +64,22 @@ replace_in_qmd_files() {
6564 # Find all .qmd files in the folder and replace the pattern
6665 find " $folder_path " -type f -name " *.qmd" -exec sed -i " s|$old_pattern |$new_pattern |g" {} +
6766 done
67+
68+ # After replacements, delete multiple website: fields
69+ find " $folder_path " -type f -name " *.qmd" -exec bash -c '
70+ for file; do
71+ count=$(grep -c "^website:" "$file")
72+ if [ "$count" -gt 1 ]; then
73+ # Use awk to comment out all but the first website: line
74+ awk "\$0 ~ /^website:/{if (++n > 1) sub(/^/, \"# \")}1" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
75+ echo "File $file: $count ' website:' lines, all but the first commented."
76+ fi
77+ done
78+ ' bash {} +
6879}
6980
7081
82+
7183# Function to update the last_commit_sha in repo_fetch.json
7284update_commit_sha () {
7385 local old_commit_sha=" $1 "
@@ -88,7 +100,6 @@ update_commit_sha() {
88100 echo " Updated last_commit_sha from ${old_commit_sha: 0: 6} ... to ${new_commit_sha: 0: 6} ... in $json_file "
89101}
90102
91-
92103# Main script
93104main () {
94105 local json_file=" scripts/2_repo_fetch.json"
@@ -126,18 +137,18 @@ main() {
126137 echo " Commit " ${new_commit_sha: 0: 6} " found for $path_to_folder_to_synchronize_from "
127138
128139 # Debug
129- echo " will perform the cloning with params
130- last commit : " $last_commit_sha "
131- new_commit_sha : " $new_commit_sha "
132- owner: " $owner "
133- repo: " $repo "
134- path: " $path "
135- path_to_folder_to_synchronize_to: " $path_to_folder_to_synchronize_to "
136- replacement: " ${replacements: 0: 20} " "
140+ # echo "will perform the cloning with params
141+ # last commit : "$last_commit_sha"
142+ # new_commit_sha : "$new_commit_sha"
143+ # owner: "$owner"
144+ # repo: "$repo"
145+ # path: "$path"
146+ # path_to_folder_to_synchronize_to: "$path_to_folder_to_synchronize_to"
147+ # replacement: "${replacements:0:20}... ""
137148
138149 # # Delete branch
139150 git branch -D origin/auto_fetch
140- git branch -d auto_fetch
151+ git branch -D auto_fetch
141152
142153 # Create a branch only if it hasn't been created yet
143154 if [ " $branch_created " = false ]; then
@@ -161,7 +172,7 @@ main() {
161172 # Commit the changes
162173 git add " $path_to_folder_to_synchronize_to " " $json_file "
163174 git commit -m " Update $path_to_folder_to_synchronize_to based on commit $new_commit_sha made to $path_to_folder_to_synchronize_from "
164- # # git push
175+ # git push
165176 else
166177 echo " No new commit since ${last_commit_sha: 0: 6} found for $path_to_folder_to_synchronize_from "
167178 fi
0 commit comments