Skip to content

Commit 08f936e

Browse files
authored
Port to zensical (#443)
Work around the missing privacy plugin by manually downloading the CDN provided files in a post-processing step.
1 parent 989ab9b commit 08f936e

7 files changed

Lines changed: 182 additions & 410 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
2727

2828
- run: |
29-
uv run properdocs build
29+
uv run zensical build --clean --config-file mkdocs.yml
30+
uv run python localize_cdn.py
3031
uv run python news2rss.py -f site/news/index.html -o site/news.xml
3132
3233
- name: Upload for pages

‎README.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
## Overview
1717

1818
This website is written in Markdown and gets built to a static website using
19-
[properdocs](https://properdocs.org/) and a modified version of the [mkdocs-material
20-
theme](https://squidfunk.github.io/mkdocs-material). Any new commits to the
19+
[Zensical](https://zensical.org/). Any new commits to the
2120
`main` branch will auto deploy to [GitHub pages](https://pages.github.com) using
2221
[a GitHub action](https://github.com/actions/deploy-pages). The resulting
2322
website is reachable under https://msys2.github.io and https://www.msys2.org.
@@ -29,14 +28,14 @@ For small changes:
2928

3029
* Just use the online editor on GitHub and use the Markdown preview to inspect your changes
3130
* Open a PR with your changes in case you don't have commit rights
32-
* **Note:** The Markdown dialect and extensions understood by properdocs and GitHub is
31+
* **Note:** The Markdown dialect and extensions understood by Zensical and GitHub are
3332
slightly different, so double check that the deployed website matches what you
3433
expected
3534
* **Note:** Every page on the website has a small "edit" icon in the top right corner which leads you straight to the online editor for that page
3635

3736
For larger changes:
3837

39-
* `uv run properdocs serve`
38+
* `uv run zensical serve --config-file mkdocs.yml`
4039
* Access http://127.0.0.1:8000 - any changes to the sources should be
4140
immediately visible in your browser
4241
* Open a PR with your changes or just push them if you have commit rights

‎localize_cdn.py‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import re
5+
from pathlib import Path
6+
from urllib.parse import urlsplit
7+
from urllib.request import Request, urlopen
8+
9+
10+
CDN_URL_RE = re.compile(
11+
rb"https://(?:unpkg\.com|cdn\.jsdelivr\.net)/[A-Za-z0-9@%_+./?=&~-]+"
12+
)
13+
def download(url: str, destination: Path) -> None:
14+
request = Request(url, headers={"User-Agent": "msys2.org site builder"})
15+
with urlopen(request, timeout=120) as response:
16+
content = response.read()
17+
18+
destination.parent.mkdir(parents=True, exist_ok=True)
19+
destination.write_bytes(content)
20+
21+
22+
def local_path(site_dir: Path, url: str) -> Path:
23+
parsed = urlsplit(url)
24+
path = parsed.path.lstrip("/")
25+
if not path or path.endswith("/"):
26+
raise ValueError(f"CDN URL does not identify a file: {url}")
27+
if parsed.netloc == "unpkg.com" and "/" not in path:
28+
path += "/index.js"
29+
return site_dir / "assets" / "vendor" / parsed.netloc / path
30+
31+
32+
def root_relative(site_dir: Path, path: Path) -> str:
33+
return "/" + path.relative_to(site_dir).as_posix()
34+
35+
36+
def localize(site_dir: Path) -> None:
37+
javascript_files = sorted(site_dir.rglob("*.js"))
38+
if not javascript_files:
39+
raise FileNotFoundError(f"No JavaScript files found in {site_dir}")
40+
41+
references = {
42+
match.group().decode("ascii")
43+
for path in javascript_files
44+
for match in CDN_URL_RE.finditer(path.read_bytes())
45+
}
46+
replacements = {}
47+
for url in sorted(references):
48+
if "pyodide" in urlsplit(url).path:
49+
continue
50+
51+
destination = local_path(site_dir, url)
52+
download(url, destination)
53+
replacements[url] = root_relative(site_dir, destination)
54+
55+
for path in javascript_files:
56+
content = path.read_bytes()
57+
for url, replacement in replacements.items():
58+
content = content.replace(url.encode(), replacement.encode())
59+
path.write_bytes(content)
60+
61+
print(f"Localized {len(replacements)} CDN references")
62+
63+
64+
def main() -> None:
65+
parser = argparse.ArgumentParser(
66+
description="Download CDN assets referenced by generated JavaScript"
67+
)
68+
parser.add_argument("site_dir", nargs="?", default="site", type=Path)
69+
args = parser.parse_args()
70+
localize(args.site_dir.resolve())
71+
72+
73+
if __name__ == "__main__":
74+
main()

‎mkdocs.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ docs_dir: web/
44
theme:
55
font: false
66
name: material
7+
variant: classic
78
logo: 'logo.svg'
89
favicon: 'favicon.ico'
910
palette:
@@ -94,8 +95,8 @@ markdown_extensions:
9495
- pymdownx.critic
9596
- pymdownx.details
9697
- pymdownx.emoji:
97-
emoji_index: !!python/name:material.extensions.emoji.twemoji
98-
emoji_generator: !!python/name:material.extensions.emoji.to_svg
98+
emoji_index: !!python/name:zensical.extensions.emoji.twemoji
99+
emoji_generator: !!python/name:zensical.extensions.emoji.to_svg
99100
- pymdownx.inlinehilite
100101
- pymdownx.magiclink
101102
- pymdownx.mark
@@ -185,4 +186,3 @@ nav:
185186
- 'privacy.md'
186187
- 'contact.md'
187188
- 'codeofconduct.md'
188-

‎overrides/main.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
{% endif %}
99
<meta property="og:type" content="website" />
1010
<meta property="og:title" content="{{ title }}" />
11-
{%- if page.is_homepage %}
11+
{% if page.meta and page.meta.description %}
12+
<meta property="og:description" content="{{ page.meta.description }}" />
13+
{% elif config.site_description %}
1214
<meta property="og:description" content="{{ config.site_description }}" />
13-
{% else %}{%- if page %}
14-
<meta property="og:description" content="{{ page.meta.summary }}" />
15-
{% endif %}{% endif %}
15+
{% endif %}
1616
<meta property="og:url" content="{{ page.canonical_url }}" />
1717
<meta property="og:image" content="https://www.msys2.org/logo.png" />
1818
<meta property="og:image:type" content="image/png" />

‎pyproject.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ requires-python = ">=3.10,<4.0"
77

88
[dependency-groups]
99
dev = [
10-
"properdocs>=1.6.7,<2",
11-
"mkdocs-material>=9.5.0,<10",
12-
"mkdocs-redirects>=1.2.2",
10+
"zensical>=0.0.58,<0.1",
1311
"beautifulsoup4>=4.13.4,<5",
1412
]
1513

1614
[tool.uv]
1715
package = false
1816
exclude-newer = "7 days"
17+
exclude-newer-package = { zensical = false }
1918

2019
[tool.poetry]
2120
package-mode = false

0 commit comments

Comments
 (0)