Skip to content

Commit c4dcef7

Browse files
Merge pull request #13 from merendamattia/auto-update-website
Prima versione della creazione dinamica del sitoweb con gli appunti
2 parents c83185c + 03496d3 commit c4dcef7

File tree

4 files changed

+128
-57
lines changed

4 files changed

+128
-57
lines changed

.github/workflows/sync_and_build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Sync and Build Website
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
schedule:
9+
- cron: '0 0 * * *' # Esegui ogni giorno a mezzanotte UTC
10+
workflow_dispatch: # Permette di avviare manualmente l'Action
11+
12+
jobs:
13+
sync_repositories:
14+
name: Sync and Build Website
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout Website Repository
19+
uses: actions/checkout@v3
20+
21+
- name: Configure Git
22+
run: |
23+
git config --global user.name "GitHub Actions"
24+
git config --global user.email "actions@github.com"
25+
26+
- name: Run Sync Script
27+
run: bash scripts/sync_repos.sh
28+
29+
- name: Commit and Push
30+
run: |
31+
git pull
32+
git add .
33+
git status
34+
if git diff --cached --quiet; then
35+
echo "No changes to commit."
36+
else
37+
git commit -m "Updated website"
38+
git push
39+
fi
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

repository/index.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

scripts/repos.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LIeC
2+
MdP

scripts/sync_repos.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)