1
+ #! /bin/bash
2
+
3
+ # Configura le directory
4
+ SITE_DIR=" repository"
5
+ REPOS_FILE=" scripts/repos.txt"
6
+ TMP_REPO=" tmp_repo"
7
+ USERNAME=" unipr-org"
8
+
9
+ # Pulizia e preparazione directory
10
+ rm -rf $SITE_DIR
11
+ mkdir -p $SITE_DIR
12
+
13
+ # Verifica che il file esista
14
+ if [[ ! -f " $REPOS_FILE " ]]; then
15
+ echo " Error: File not found at '$REPOS_FILE '"
16
+ exit 1
17
+ fi
18
+
19
+ # Leggi il file riga per riga e stampa il contenuto
20
+ while IFS= read -r repo; do
21
+ echo " Processing $repo ..."
22
+
23
+ if [[ -z " $repo " ]]; then continue ; fi # Salta righe vuote
24
+
25
+ rm -rf $TMP_REPO
26
+ mkdir $TMP_REPO
27
+ git clone --depth=1 https://github.com/$USERNAME /$repo .git $TMP_REPO > /dev/null
28
+
29
+ repo_dir=" $SITE_DIR /$repo "
30
+ mkdir -p $repo_dir
31
+
32
+ tmp_artifacts_html=" $TMP_REPO /artifacts/html"
33
+
34
+ if [[ -d " $tmp_artifacts_html " ]]; then
35
+ cp -r $tmp_artifacts_html /* $repo_dir /
36
+ else
37
+ echo " Warning: No artifacts/html directory in $repo "
38
+ fi
39
+ rm -rf $TMP_REPO
40
+
41
+ done < " $REPOS_FILE "
42
+
43
+ INDEX=$SITE_DIR /index.md
44
+
45
+ # Genera l'homepage
46
+ echo " <html> <head>
47
+ <title>Unipr Repositories</title>
48
+ </head> <body>
49
+ <h1>Repositories</h1> <ul>" > $INDEX
50
+
51
+ for repo_dir in $SITE_DIR /* ; do
52
+ repo_name=$( basename $repo_dir )
53
+ if [[ " $repo_name " == " index.md" ]]; then continue ; fi
54
+
55
+ echo " <li><a href=\" $repo_name \" >$repo_name </a></li>" >> $INDEX
56
+
57
+ # Genera la pagina per ogni repository
58
+ echo " <html> <head> <title>$repo_name </title> </head> <body>
59
+ <h1>Files in $repo_name </h1> <ul>" > " $repo_dir /index.md"
60
+
61
+ for file in " $repo_dir " /* ; do
62
+ file_name=$( basename " $file " )
63
+ if [[ " $file_name " == " index.md" ]]; then continue ; fi
64
+ if [[ " $file_name " == " images" ]]; then continue ; fi
65
+
66
+ # Rimuove i tag <style>...</style> dal file
67
+ if [[ " $file " == * .html ]]; then
68
+ echo " Processing file: $file (removing <style> tags)"
69
+ sed ' /<style/,/<\/style>/d' " $file " > " $file .tmp" && mv " $file .tmp" " $file " # Rimuove lo stile css
70
+
71
+ # Rimuove la prima riga del file (quella che contiene <!DOCTYPE html>)
72
+ tail -n +2 " $file " > " $file .tmp" && mv " $file .tmp" " $file "
73
+
74
+ # Cambia l'estensione da .html a .md
75
+ mv " $file " " ${file% .html} .md"
76
+ fi
77
+
78
+ echo " <li><a href=\" $file_name \" >$file_name </a></li>" >> " $repo_dir /index.md"
79
+
80
+ done
81
+
82
+ echo " </ul> </body> </html>" >> " $repo_dir /index.md"
83
+ done
84
+
85
+ echo " </ul> </body> </html>" >> $INDEX
0 commit comments