Skip to content

Commit

Permalink
add root index updater
Browse files Browse the repository at this point in the history
  • Loading branch information
cibere committed Jan 13, 2025
1 parent 1cba22f commit 2b44909
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/scripts/index_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>rtfm docs</title>
</head>
<body>
<h3>Documentation Versions</h3>
<ul>
{% for version in versions %}
<li>
<a href="/{{ version }}">{{ version }}</a>
</li>
{% endfor %}
</ul>
</body>
</html>
1 change: 1 addition & 0 deletions .github/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jinja2==3.1.5
31 changes: 31 additions & 0 deletions .github/scripts/update_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pathlib import Path
import os
import re
import jinja2

VERSION_RE = re.compile(
r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<micro>[0-9]+)(?:(?P<level>[ab])(?P<serial>[0-9]*))?"
)


def main():
scripts_dir = Path(os.path.dirname(__file__))
root_dir = Path(*scripts_dir.parts[:-2])

index_fp = root_dir / "index.html"

versions = [
folder.name
for folder in root_dir.glob("*")
if folder.is_dir and VERSION_RE.fullmatch(folder.name)
]

env = jinja2.Environment(loader=jinja2.PackageLoader("update_index", ""))
template = env.get_template("index_template.html")

with index_fp.open("w", encoding="UTF-8") as f:
f.write(template.render(versions=versions))


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions .github/workflows/update_index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Update Root Index

on:
push:
branches:
- gh-pages

jobs:
update_index:
runs-on: ubuntu-latest
permissions:
contents: write
env:
python_ver: 3.13

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ env.python_ver }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.python_ver }}

- name: Goto scripts dir
run: |
cd .github
cd scripts
- name: Install dependencies
run: pip install -r requirements.txt

- name: Update Index
run: |
python update_index.py

0 comments on commit 2b44909

Please sign in to comment.