Skip to content

Commit 959aef8

Browse files
TaiSakumaclaude
andauthored
feat: styled index.html from template with update-index action (#22)
## Summary - Add HTML template with light/dark mode, version labels, and GitHub link - Add `generate_index.py` script using `string.Template` - Extract `update-index` composite action for index.html generation - Add `update-index` step to `docs-dev.yml` so root page exists from first deploy - Move `latest/` copy to inline step in `docs-release.yml` - Move `git config` from `deploy-to-gh-pages` action to each workflow ## Test plan - [ ] Push to main → index.html generated with styling - [ ] Push a tag → `/latest/` and index.html updated - [ ] Verify light/dark mode on index page 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a8ada51 commit 959aef8

File tree

8 files changed

+144
-23
lines changed

8 files changed

+144
-23
lines changed

.github/actions/deploy-to-gh-pages/action.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ runs:
2323
- id: deploy
2424
shell: bash
2525
run: |
26-
git config user.name "github-actions[bot]"
27-
git config user.email "github-actions[bot]@users.noreply.github.com"
2826
TARGET="${{ inputs.target }}"
2927
git fetch origin gh-pages 2>/dev/null || true
3028
if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Update index.html
2+
description: Regenerate index.html, commit and push
3+
4+
inputs:
5+
repo-name:
6+
description: Repository name for the index page title
7+
required: true
8+
repo-url:
9+
description: Repository URL for the GitHub link
10+
required: true
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- shell: bash
16+
run: |
17+
python "${{ github.action_path }}/generate_index.py" \
18+
"${{ inputs.repo-name }}" \
19+
"${{ inputs.repo-url }}"
20+
git add index.html
21+
git diff --cached --quiet || git commit -m "Update index.html"
22+
git push origin gh-pages
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'''Generate index.html listing all doc versions on gh-pages.'''
2+
import re
3+
import sys
4+
from pathlib import Path
5+
from string import Template
6+
7+
8+
def find_versions() -> list[str]:
9+
'''Find version directories (e.g., 0.2.1, 1.0.0) sorted descending.'''
10+
dirs = [
11+
d.name for d in Path('.').iterdir()
12+
if d.is_dir() and re.match(r'\d', d.name)
13+
]
14+
dirs.sort(key=lambda v: [int(x) for x in v.split('.')], reverse=True)
15+
return dirs
16+
17+
18+
def find_latest_version(versions: list[str]) -> str | None:
19+
'''Return the version that /latest/ points to, if any.'''
20+
if not versions or not Path('latest').is_dir():
21+
return None
22+
return versions[0]
23+
24+
25+
def build_version_list(versions: list[str], latest_version: str | None) -> str:
26+
'''Build HTML list items for all versions.'''
27+
lines: list[str] = []
28+
if latest_version:
29+
lines.append(f' <li><a href="latest/">latest</a> <span class="meta">({latest_version})</span></li>')
30+
if Path('dev').is_dir():
31+
lines.append(' <li><a href="dev/">dev</a></li>')
32+
for v in versions:
33+
lines.append(f' <li><a href="{v}/">{v}</a></li>')
34+
return '\n'.join(lines)
35+
36+
37+
def main() -> None:
38+
repo_name = sys.argv[1]
39+
repo_url = sys.argv[2]
40+
41+
template_path = Path(__file__).parent / 'index.html'
42+
template = Template(template_path.read_text())
43+
44+
versions = find_versions()
45+
latest_version = find_latest_version(versions)
46+
version_list = build_version_list(versions, latest_version)
47+
48+
html = template.substitute(
49+
repo_name=repo_name,
50+
repo_url=repo_url,
51+
version_list=version_list,
52+
)
53+
54+
Path('index.html').write_text(html)
55+
56+
57+
main()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>$repo_name</title>
6+
<style>
7+
body {
8+
font-family: system-ui, sans-serif;
9+
max-width: 600px;
10+
margin: 2rem auto;
11+
padding: 0 1rem;
12+
}
13+
a { color: #1a73e8; text-decoration: none; }
14+
a:hover { text-decoration: underline; }
15+
ul { list-style: none; padding: 0; }
16+
li { padding: 0.3rem 0; }
17+
.meta { color: #666; font-size: 0.9rem; }
18+
footer { margin-top: 2rem; font-size: 0.9rem; }
19+
@media (prefers-color-scheme: dark) {
20+
body { background: #1a1a1a; color: #e0e0e0; }
21+
a { color: #8ab4f8; }
22+
.meta { color: #999; }
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<h1>$repo_name documentation</h1>
28+
<ul>
29+
$version_list
30+
</ul>
31+
<footer><a href="$repo_url">GitHub</a></footer>
32+
</body>
33+
</html>

.github/workflows/docs-dev.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ jobs:
2525
with:
2626
subdir: dev
2727

28+
- name: Configure git
29+
run: |
30+
git config user.name "github-actions[bot]"
31+
git config user.email "github-actions[bot]@users.noreply.github.com"
32+
2833
- uses: ./.github/actions/deploy-to-gh-pages
2934
with:
3035
site-dir: ${{ steps.build.outputs.site-dir }}
3136
target: dev
3237
commit-message: Deploy dev docs
38+
39+
- uses: ./.github/actions/update-index
40+
with:
41+
repo-name: ${{ github.event.repository.name }}
42+
repo-url: ${{ github.event.repository.html_url }}

.github/workflows/docs-pr-cleanup.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v6
1919

20-
- name: Remove PR preview
20+
- name: Configure git
2121
run: |
2222
git config user.name "github-actions[bot]"
2323
git config user.email "github-actions[bot]@users.noreply.github.com"
24+
25+
- name: Remove PR preview
26+
run: |
2427
git fetch origin gh-pages 2>/dev/null || true
2528
if ! git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
2629
echo "gh-pages branch does not exist, nothing to clean up"

.github/workflows/docs-pr-preview.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ jobs:
6161
name: docs-preview
6262
path: ${{ env.SITE_DIR }}
6363

64+
- name: Configure git
65+
run: |
66+
git config user.name "github-actions[bot]"
67+
git config user.email "github-actions[bot]@users.noreply.github.com"
68+
6469
# Reference the action from @main so deploy logic always comes from the
6570
# trusted main branch.
6671
- uses: TaiSakuma/improved-octo-fortnight/.github/actions/deploy-to-gh-pages@main

.github/workflows/docs-release.yml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,25 @@ jobs:
3636
with:
3737
subdir: ${{ steps.version.outputs.version }}
3838

39+
- name: Configure git
40+
run: |
41+
git config user.name "github-actions[bot]"
42+
git config user.email "github-actions[bot]@users.noreply.github.com"
43+
3944
- uses: ./.github/actions/deploy-to-gh-pages
4045
with:
4146
site-dir: ${{ steps.build.outputs.site-dir }}
4247
target: ${{ steps.version.outputs.version }}
4348
commit-message: Deploy docs for v${{ steps.version.outputs.version }}
4449

45-
- name: Update latest and index.html
50+
- name: Update latest
4651
run: |
47-
TARGET="${{ steps.version.outputs.version }}"
4852
rm -rf latest
4953
cp -r "${{ steps.build.outputs.site-dir }}" latest
50-
# Generate root index.html
51-
REPO_NAME="${{ github.event.repository.name }}"
52-
{
53-
echo '<!DOCTYPE html>'
54-
echo "<html><head><meta charset=\"utf-8\"><title>${REPO_NAME}</title></head>"
55-
echo "<body><h1>${REPO_NAME} documentation</h1><ul>"
56-
echo '<li><a href="latest/">latest</a></li>'
57-
if [ -d dev ]; then
58-
echo '<li><a href="dev/">dev</a></li>'
59-
fi
60-
for d in $(find . -maxdepth 1 -type d -name '[0-9]*' | sed 's|^\./||' | sort -rV); do
61-
echo "<li><a href=\"$d/\">$d</a></li>"
62-
done
63-
echo '</ul></body></html>'
64-
} > index.html
65-
git add latest index.html
66-
git diff --cached --quiet || git commit -m "Update latest and index.html for v${TARGET}"
67-
git push origin gh-pages
54+
git add latest
55+
git commit -m "Update latest"
56+
57+
- uses: ./.github/actions/update-index
58+
with:
59+
repo-name: ${{ github.event.repository.name }}
60+
repo-url: ${{ github.event.repository.html_url }}

0 commit comments

Comments
 (0)