|
| 1 | +name: 🌐 Mise à jour section YouTube du site |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [gh-pages] |
| 6 | + paths: |
| 7 | + - 'assets/data/youtube-videos.json' |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + update-music-page: |
| 15 | + name: Injecter les vidéos dans music.html |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + ref: gh-pages |
| 23 | + |
| 24 | + - name: Setup Python |
| 25 | + uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: '3.11' |
| 28 | + |
| 29 | + - name: Injecter les vidéos YouTube dans music.html |
| 30 | + run: | |
| 31 | + python3 << 'EOF' |
| 32 | + import json |
| 33 | + import re |
| 34 | +
|
| 35 | + with open('assets/data/youtube-videos.json', 'r', encoding='utf-8') as f: |
| 36 | + videos = json.load(f) |
| 37 | +
|
| 38 | + # Générer le HTML de la grille vidéos |
| 39 | + cards = '' |
| 40 | + for v in videos: |
| 41 | + if v['id'] == 'placeholder': |
| 42 | + continue |
| 43 | + cards += f''' |
| 44 | + <a href="{v['url']}" target="_blank" rel="noopener noreferrer" class="yt-card"> |
| 45 | + <div class="yt-thumb"> |
| 46 | + <img src="{v['thumbnail']}" alt="{v['title']}" loading="lazy" width="320" height="180"> |
| 47 | + <span class="yt-play">▶</span> |
| 48 | + </div> |
| 49 | + <p class="yt-title">{v['title']}</p> |
| 50 | + <span class="yt-date">{v['published']}</span> |
| 51 | + </a>''' |
| 52 | +
|
| 53 | + youtube_block = f'''<!-- YOUTUBE-AUTO-START --> |
| 54 | + <div class="yt-grid"> |
| 55 | + <a href="https://www.youtube.com/@DavidKRKofficial" target="_blank" rel="noopener noreferrer" class="yt-channel-link">🎬 Voir toutes les vidéos sur YouTube</a> |
| 56 | + <div class="yt-cards">{cards} |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + <!-- YOUTUBE-AUTO-END -->''' |
| 60 | + |
| 61 | + with open('music.html', 'r', encoding='utf-8') as f: |
| 62 | + content = f.read() |
| 63 | + |
| 64 | + # Remplacer le bloc existant ou injecter avant </main> |
| 65 | + pattern = r'<!-- YOUTUBE-AUTO-START -->.*?<!-- YOUTUBE-AUTO-END -->' |
| 66 | + if re.search(pattern, content, re.DOTALL): |
| 67 | + content = re.sub(pattern, youtube_block, content, flags=re.DOTALL) |
| 68 | + else: |
| 69 | + content = content.replace('</main>', youtube_block + '\n </main>') |
| 70 | + |
| 71 | + with open('music.html', 'w', encoding='utf-8') as f: |
| 72 | + f.write(content) |
| 73 | + |
| 74 | + print('music.html mis à jour avec les vidéos YouTube !') |
| 75 | + EOF |
| 76 | + |
| 77 | + - name: Injecter le CSS YouTube dans assets/css/style.css |
| 78 | + run: | |
| 79 | + if ! grep -q 'yt-grid' assets/css/style.css; then |
| 80 | + cat >> assets/css/style.css << 'CSSEOF' |
| 81 | +
|
| 82 | +/* === YouTube Auto-Section === */ |
| 83 | +.yt-grid { max-width: 960px; margin: 2rem auto; padding: 0 1rem; text-align: center; } |
| 84 | +.yt-channel-link { display: inline-block; margin-bottom: 1.5rem; color: #ff0000; font-weight: bold; font-size: 1.1rem; text-decoration: none; } |
| 85 | +.yt-channel-link:hover { opacity: 0.8; } |
| 86 | +.yt-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; } |
| 87 | +.yt-card { display: flex; flex-direction: column; background: rgba(0,0,0,0.45); border-radius: 10px; overflow: hidden; text-decoration: none; color: #fff; transition: transform 0.2s ease, box-shadow 0.2s ease; } |
| 88 | +.yt-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(255,0,0,0.2); } |
| 89 | +.yt-thumb { position: relative; } |
| 90 | +.yt-thumb img { width: 100%; height: 180px; object-fit: cover; display: block; } |
| 91 | +.yt-play { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 2.5rem; opacity: 0.85; pointer-events: none; } |
| 92 | +.yt-title { padding: 0.6rem 0.8rem 0.2rem; font-size: 0.9rem; font-weight: 600; text-align: left; } |
| 93 | +.yt-date { padding: 0 0.8rem 0.8rem; font-size: 0.75rem; color: #aaa; text-align: left; } |
| 94 | +CSSEOF |
| 95 | + echo 'CSS YouTube ajouté à style.css' |
| 96 | + else |
| 97 | + echo 'CSS YouTube déjà présent dans style.css' |
| 98 | + fi |
| 99 | + |
| 100 | + - name: Commit et push |
| 101 | + run: | |
| 102 | + git config user.name "github-actions[bot]" |
| 103 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 104 | + git add music.html assets/css/style.css |
| 105 | + if git diff --staged --quiet; then |
| 106 | + echo "Aucun changement à commiter." |
| 107 | + else |
| 108 | + git commit -m "🌐 Auto-update: section YouTube mise à jour sur music.html" |
| 109 | + git push |
| 110 | + fi |
0 commit comments