56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""V133 - Generate wiki index for session articles V100-V130"""
|
|
import os, re, json, glob
|
|
|
|
wiki_dir = '/var/www/html/wiki'
|
|
articles = sorted(glob.glob(f'{wiki_dir}/V1[0-3]*.md'))
|
|
|
|
index_entries = []
|
|
for path in articles:
|
|
name = os.path.basename(path)
|
|
size = os.path.getsize(path)
|
|
# Read first non-empty line as title
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
# Find title (first # heading)
|
|
title_m = re.search(r'^#\s*(.+?)$', content, re.MULTILINE)
|
|
title = title_m.group(1).strip() if title_m else name.replace('.md', '')
|
|
# Extract V-number from filename
|
|
vm = re.match(r'V(\d+)', name)
|
|
vnum = int(vm.group(1)) if vm else 0
|
|
index_entries.append({
|
|
'v': vnum,
|
|
'filename': name,
|
|
'title': title,
|
|
'size': size
|
|
})
|
|
|
|
index_entries.sort(key=lambda x: x['v'])
|
|
|
|
# Generate markdown index
|
|
md = ["# Wiki Index · Articles V100-V130 · Session 20-21 avril 2026",
|
|
"",
|
|
f"_Auto-generated: {len(index_entries)} articles_",
|
|
"",
|
|
"## Articles",
|
|
""]
|
|
for e in index_entries:
|
|
md.append(f"- **[{e['filename']}](/wiki/{e['filename']})** — {e['title']} ({e['size']}B)")
|
|
|
|
md_content = '\n'.join(md)
|
|
|
|
# Write index
|
|
with open(f'{wiki_dir}/INDEX-V100-V130.md', 'w', encoding='utf-8') as f:
|
|
f.write(md_content)
|
|
|
|
# Also JSON for API consumption
|
|
with open('/var/www/html/api/wiki-index-session.json', 'w') as f:
|
|
json.dump({
|
|
'generated_at': __import__('time').strftime('%Y-%m-%dT%H:%M:%S'),
|
|
'count': len(index_entries),
|
|
'articles': index_entries
|
|
}, f, indent=2)
|
|
|
|
print(f"INDEX written: {len(index_entries)} articles")
|
|
print(md_content[:500])
|