Skip to content

Commit e813b0b

Browse files
Copilotm-aciek
andauthored
Generate per-version index.html listings with path, filename, timestamp, and size (#19)
* Add per-version directory listing generation in workflows Agent-Logs-Url: https://github.com/m-aciek/python-docs-offline/sessions/349dba21-5638-4730-931a-897a2d1ebfed Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com> * Improve generated directory listing HTML metadata and links Agent-Logs-Url: https://github.com/m-aciek/python-docs-offline/sessions/349dba21-5638-4730-931a-897a2d1ebfed Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com> * Use standards-compliant HTML attribute quoting in listings Agent-Logs-Url: https://github.com/m-aciek/python-docs-offline/sessions/349dba21-5638-4730-931a-897a2d1ebfed Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
1 parent d4cd03d commit e813b0b

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/build.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,52 @@ jobs:
236236
! -name "python-*-pdf-logs.zip" \
237237
-exec cp {} _site/${{ needs.prepare.outputs.major_minor }}/ \;
238238
239+
- name: Generate per-version directory listing
240+
run: |
241+
python - <<'PY'
242+
import re
243+
from datetime import datetime, timezone
244+
from html import escape
245+
from pathlib import Path
246+
from urllib.parse import quote
247+
248+
root = Path("_site")
249+
version_pattern = re.compile(r"^\d+\.\d+$")
250+
for version_dir in sorted(
251+
p for p in root.iterdir() if p.is_dir() and version_pattern.match(p.name)
252+
):
253+
files = sorted(
254+
p for p in version_dir.iterdir() if p.is_file() and p.name != "index.html"
255+
)
256+
rows = []
257+
for file_path in files:
258+
stat = file_path.stat()
259+
timestamp = datetime.fromtimestamp(stat.st_mtime, timezone.utc).strftime(
260+
"%Y-%m-%d %H:%M:%S UTC"
261+
)
262+
rows.append(
263+
f'<tr><td><a href="{quote(file_path.name)}">{escape(file_path.name)}</a></td><td>{timestamp}</td><td>{stat.st_size}</td></tr>'
264+
)
265+
266+
relative_path = f"/{version_dir.relative_to(root).as_posix()}/"
267+
html = [
268+
"<!doctype html>",
269+
'<html lang="en">',
270+
'<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Directory listing</title></head>',
271+
"<body>",
272+
f"<h1>Path: {escape(relative_path)}</h1>",
273+
"<table>",
274+
'<thead><tr><th scope="col">Filename</th><th scope="col">Timestamp (UTC)</th><th scope="col">Size (bytes)</th></tr></thead>',
275+
"<tbody>",
276+
*rows,
277+
"</tbody>",
278+
"</table>",
279+
"</body>",
280+
"</html>",
281+
]
282+
(version_dir / "index.html").write_text("\n".join(html) + "\n", encoding="utf-8")
283+
PY
284+
239285
- name: Upload Pages artifact
240286
uses: actions/upload-pages-artifact@v3
241287
with:

.github/workflows/schedule.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,52 @@ jobs:
104104
rm -rf _site/3
105105
ln -s "$stable" _site/3
106106
107+
- name: Generate per-version directory listing
108+
run: |
109+
python - <<'PY'
110+
import re
111+
from datetime import datetime, timezone
112+
from html import escape
113+
from pathlib import Path
114+
from urllib.parse import quote
115+
116+
root = Path("_site")
117+
version_pattern = re.compile(r"^\d+\.\d+$")
118+
for version_dir in sorted(
119+
p for p in root.iterdir() if p.is_dir() and version_pattern.match(p.name)
120+
):
121+
files = sorted(
122+
p for p in version_dir.iterdir() if p.is_file() and p.name != "index.html"
123+
)
124+
rows = []
125+
for file_path in files:
126+
stat = file_path.stat()
127+
timestamp = datetime.fromtimestamp(stat.st_mtime, timezone.utc).strftime(
128+
"%Y-%m-%d %H:%M:%S UTC"
129+
)
130+
rows.append(
131+
f'<tr><td><a href="{quote(file_path.name)}">{escape(file_path.name)}</a></td><td>{timestamp}</td><td>{stat.st_size}</td></tr>'
132+
)
133+
134+
relative_path = f"/{version_dir.relative_to(root).as_posix()}/"
135+
html = [
136+
"<!doctype html>",
137+
'<html lang="en">',
138+
'<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Directory listing</title></head>',
139+
"<body>",
140+
f"<h1>Path: {escape(relative_path)}</h1>",
141+
"<table>",
142+
'<thead><tr><th scope="col">Filename</th><th scope="col">Timestamp (UTC)</th><th scope="col">Size (bytes)</th></tr></thead>',
143+
"<tbody>",
144+
*rows,
145+
"</tbody>",
146+
"</table>",
147+
"</body>",
148+
"</html>",
149+
]
150+
(version_dir / "index.html").write_text("\n".join(html) + "\n", encoding="utf-8")
151+
PY
152+
107153
- name: Upload Pages artifact
108154
uses: actions/upload-pages-artifact@v3
109155
with:

0 commit comments

Comments
 (0)