77 lines
2.6 KiB
YAML
77 lines
2.6 KiB
YAML
name: Fix README
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
fix:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout (sparse - readme + json metadata only)
|
|
uses: actions/checkout@v4
|
|
with:
|
|
sparse-checkout: |
|
|
README.md
|
|
assets/*.json
|
|
sparse-checkout-cone-mode: false
|
|
fetch-depth: 1
|
|
|
|
- name: Configure Git
|
|
run: |
|
|
git config user.name 'github-actions[bot]'
|
|
git config user.email 'github-actions[bot]@users.noreply.github.com'
|
|
|
|
- name: Rebuild README from JSON metadata
|
|
run: |
|
|
python3 << 'PYEOF'
|
|
import os, json, glob
|
|
|
|
CDN_BASE = "https://raw.githubusercontent.com/yapude/wallpapers/main/assets"
|
|
|
|
header = "# Wallpaper Archive\n\nAutomated archive of wallpapers to bypass Cloudflare and prevent dead links.\n\n## Gallery\n\n| Preview | Title | Tags |\n| --- | --- | --- |\n"
|
|
|
|
rows = []
|
|
count = 0
|
|
errors = 0
|
|
|
|
for json_file in sorted(glob.glob("assets/*.json")):
|
|
try:
|
|
with open(json_file, "r", encoding="utf-8") as f:
|
|
item = json.load(f)
|
|
|
|
ext = "png" if ".png" in item.get("download_url", "") else "jpg"
|
|
item_id = item.get("id", "")
|
|
filename = f"{item_id}.{ext}"
|
|
cdn_url = f"{CDN_BASE}/{filename}"
|
|
|
|
title = item.get("title", "Wallpaper")
|
|
tags = ", ".join(item.get("tags", []))
|
|
|
|
row = f'| <img src="{cdn_url}" width="200"> | **{title}**<br>[Download]({cdn_url}) | {tags} |\n'
|
|
rows.append((item_id, row))
|
|
count += 1
|
|
except Exception as e:
|
|
errors += 1
|
|
|
|
rows.sort(key=lambda x: x[0])
|
|
|
|
chunk_size = 100000
|
|
|
|
for i in range(0, len(rows), chunk_size):
|
|
chunk = rows[i:i + chunk_size]
|
|
filename = "README.md" if i == 0 else f"README{(i//chunk_size) + 1}.md"
|
|
with open(filename, "w", encoding="utf-8") as f:
|
|
f.write(header)
|
|
for _, row in chunk:
|
|
f.write(row)
|
|
|
|
print(f"Rebuilt README with {count} wallpapers ({errors} errors) across {len(rows)//chunk_size + 1} files")
|
|
PYEOF
|
|
|
|
- name: Commit and Push
|
|
run: |
|
|
git add --sparse README*.md
|
|
git diff --cached --quiet && echo "no changes" || (git commit -m "fix: rebuild readme from archive metadata [skip ci]" && git push) |