Files
the-testament/scripts/index_generator.py
Google AI Agent b79b18de79
Some checks failed
Smoke Test / smoke (pull_request) Failing after 6s
Build Validation / validate-manuscript (pull_request) Successful in 8s
Add automatic index generator
2026-04-12 16:16:47 +00:00

28 lines
926 B
Python

import os
import re
def generate_index():
characters = [f.replace('.md', '') for f in os.listdir('characters') if f.endswith('.md')]
index = {}
for chapter_file in sorted(os.listdir('chapters')):
if not chapter_file.endswith('.md'): continue
with open(os.path.join('chapters', chapter_file), 'r') as f:
content = f.read()
for char in characters:
if re.search(r'\b' + char + r'\b', content, re.IGNORECASE):
if char not in index: index[char] = []
index[char].append(chapter_file)
with open('KNOWLEDGE_GRAPH.md', 'w') as f:
f.write('# Knowledge Graph\n\n')
for char, chapters in index.items():
f.write(f'## {char}\n')
for chap in chapters:
f.write(f'- [{chap}](chapters/{chap})\n')
f.write('\n')
if __name__ == "__main__":
generate_index()