mirror of
https://github.com/kbenestad/mdcms.git
synced 2026-06-18 07:24:31 +00:00
Add workflow: auto-update themes/index.json on theme changes
This commit is contained in:
parent
820a5f9556
commit
ba6fb719c1
1 changed files with 46 additions and 0 deletions
46
.github/workflows/update-themes-index.yml
vendored
Normal file
46
.github/workflows/update-themes-index.yml
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
name: Update themes index
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [gh-pages]
|
||||
paths:
|
||||
- 'themes/**'
|
||||
- '!themes/index.json'
|
||||
|
||||
jobs:
|
||||
update-index:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: gh-pages
|
||||
|
||||
- name: Regenerate themes/index.json
|
||||
run: |
|
||||
python3 - << 'EOF'
|
||||
import json, os
|
||||
themes_root = 'themes'
|
||||
result = {}
|
||||
for cat in sorted(os.listdir(themes_root)):
|
||||
cat_path = os.path.join(themes_root, cat)
|
||||
if not os.path.isdir(cat_path):
|
||||
continue
|
||||
files = sorted(f for f in os.listdir(cat_path) if f.endswith('.yaml'))
|
||||
themes = [{'slug': cat + '/' + f, 'label': f[:-5].replace('-', ' ')} for f in files]
|
||||
if themes:
|
||||
result[cat] = themes
|
||||
with open('themes/index.json', 'w') as fh:
|
||||
json.dump(result, fh, indent=2)
|
||||
total = sum(len(v) for v in result.values())
|
||||
print(f'Updated: {len(result)} categories, {total} themes')
|
||||
EOF
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add themes/index.json
|
||||
git diff --cached --quiet || git commit -m "Auto-update themes/index.json"
|
||||
git push
|
||||
Loading…
Reference in a new issue