-
-
Notifications
You must be signed in to change notification settings - Fork 0
Pages Manager
Last updated: 2025-11-15 23:25:22
Auto-generated from .github/scripts/pages-manager.py
TL;DR β A Python script that automatically turns Markdown documentation files into a wellβstructured GitHub Pages site.
It uses an LLM (Groq) to decide whether to create, append, or modify pages, merges content intelligently, and keeps a persistent mapping of source files to page paths.
pages-manager.py is a CIβdriven tool that:
| Feature | What it does |
|---|---|
| LLMβpowered decision making | Sends the source file name and its Markdown content to Groqβs LLM to decide where the documentation should live. |
| Smart page handling | Creates new pages, appends to existing ones, or modifies pages while preserving frontβmatter and timestamps. |
| Index generation | Builds a main index.md and perβsection index pages (e.g. api/index.md). |
| Persistent mapping | Stores a JSON mapping (.github/pages-mapping.json) that tracks which source file maps to which page and metadata. |
| CI integration | Reads a changed_files.txt list, looks up corresponding Markdown docs in docs/, and updates the GitHub Pages site in docs-site/. |
| Security & audit | Uses environment variables for the Groq API key and logs all actions to the console. |
Why use it?
When you add or modify TypeScript/JavaScript source files, you usually also update the Markdown docs. This script automates the tedious part of moving those docs into the right place on your GitHub Pages site, ensuring consistency and reducing human error.
| Export | Type | Description |
|---|---|---|
PagesManager |
Class | Core engine that scans existing pages, makes LLM decisions, applies changes, and generates indexes. |
process_docs_to_pages(doc_files: List[str]) |
Function | Highβlevel entry point that processes a list of Markdown files, updates the site, and writes a summary. |
GROQ_API_KEY |
str |
Environment variable holding the Groq API key. |
GROQ_API_URL |
str |
Endpoint for the Groq chat completions API. |
MODEL |
str |
LLM model name (openai/gpt-oss-120b). |
PAGES_DIR |
Path |
Directory where the generated GitHub Pages site lives (docs-site/). |
MAPPING_FILE |
str |
Path to the persistent JSON mapping (.github/pages-mapping.json). |
Note β The script also contains a
__main__block that can be executed directly.
# 1. Ensure the Groq API key is set
export GROQ_API_KEY="sk-..."
# 2. Create a list of changed source files (e.g. from a CI job)
echo "src/auth.ts" > changed_files.txt
echo "src/payment.ts" >> changed_files.txt
# 3. Run the manager
python .github/scripts/pages-manager.pyThe script will:
- Read
changed_files.txt. - Find corresponding Markdown docs in
docs/. - Use the LLM to decide where to place each doc.
- Create/append/modify pages under
docs-site/. - Generate
index.mdand section indexes. - Write a
pages_summary.mdand update.github/pages-mapping.json.
from pathlib import Path
from pages_manager import PagesManager
# Instantiate the manager
manager = PagesManager()
# Example: create a new page
page_path = "api/new-feature.md"
content = "# New Feature\n\nDetails about the new feature."
manager.apply_documentation_change(page_path, "create", content)
# Example: append to an existing page
section_title = "New Functionality"
new_section = "## New Functionality\n\nDescription of the new function."
manager.apply_documentation_change("api/old-module.md", "append", new_section, section_title)
# Generate indexes after changes
manager.generate_index_page()from pages_manager import process_docs_to_pages
# Suppose you have a list of Markdown docs to process
docs = [
"docs/auth.md",
"docs/payment.md",
"docs/notifications.md",
]
process_docs_to_pages(docs)| Parameter | Type | Description |
|---|---|---|
| None | β | Initializes self.mapping and self.existing_pages. |
Return β None (constructor).
| Parameter | Type | Description |
|---|---|---|
| None | β | Loads mapping from MAPPING_FILE if it exists. |
Return β A dictionary with keys: version, last_updated, file_to_page, page_metadata, site_structure.
| Parameter | Type | Description |
|---|---|---|
| None | β | Writes self.mapping to MAPPING_FILE. |
Return β None.
| Parameter | Type | Description |
|---|---|---|
| None | β | Scans PAGES_DIR for all .md files and reads their content. |
Return β Dictionary mapping relative file paths to file contents.
4.5 PagesManager.make_intelligent_decision(self, source_file: str, doc_content: str) -> Tuple[str, str, str]
| Parameter | Type | Description |
|---|---|---|
source_file |
str |
Name of the source file (e.g. auth.ts). |
doc_content |
str |
Markdown content of the documentation. |
Return β (page_path, action, reasoning) where:
-
page_pathβ Target Markdown file path (relative toPAGES_DIR). -
actionβ One of