Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0

- run: |
uv run properdocs build
uv run zensical build --clean --config-file mkdocs.yml
uv run python localize_cdn.py
uv run python news2rss.py -f site/news/index.html -o site/news.xml

- name: Upload for pages
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
## Overview

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

* Just use the online editor on GitHub and use the Markdown preview to inspect your changes
* Open a PR with your changes in case you don't have commit rights
* **Note:** The Markdown dialect and extensions understood by properdocs and GitHub is
* **Note:** The Markdown dialect and extensions understood by Zensical and GitHub are
slightly different, so double check that the deployed website matches what you
expected
* **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

For larger changes:

* `uv run properdocs serve`
* `uv run zensical serve --config-file mkdocs.yml`
* Access http://127.0.0.1:8000 - any changes to the sources should be
immediately visible in your browser
* Open a PR with your changes or just push them if you have commit rights
Expand Down
74 changes: 74 additions & 0 deletions localize_cdn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3

import argparse
import re
from pathlib import Path
from urllib.parse import urlsplit
from urllib.request import Request, urlopen


CDN_URL_RE = re.compile(
rb"https://(?:unpkg\.com|cdn\.jsdelivr\.net)/[A-Za-z0-9@%_+./?=&~-]+"
)
def download(url: str, destination: Path) -> None:
request = Request(url, headers={"User-Agent": "msys2.org site builder"})
with urlopen(request, timeout=120) as response:
content = response.read()

destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_bytes(content)


def local_path(site_dir: Path, url: str) -> Path:
parsed = urlsplit(url)
path = parsed.path.lstrip("/")
if not path or path.endswith("/"):
raise ValueError(f"CDN URL does not identify a file: {url}")
if parsed.netloc == "unpkg.com" and "/" not in path:
path += "/index.js"
return site_dir / "assets" / "vendor" / parsed.netloc / path


def root_relative(site_dir: Path, path: Path) -> str:
return "/" + path.relative_to(site_dir).as_posix()


def localize(site_dir: Path) -> None:
javascript_files = sorted(site_dir.rglob("*.js"))
if not javascript_files:
raise FileNotFoundError(f"No JavaScript files found in {site_dir}")

references = {
match.group().decode("ascii")
for path in javascript_files
for match in CDN_URL_RE.finditer(path.read_bytes())
}
replacements = {}
for url in sorted(references):
if "pyodide" in urlsplit(url).path:
continue

destination = local_path(site_dir, url)
download(url, destination)
replacements[url] = root_relative(site_dir, destination)

for path in javascript_files:
content = path.read_bytes()
for url, replacement in replacements.items():
content = content.replace(url.encode(), replacement.encode())
path.write_bytes(content)

print(f"Localized {len(replacements)} CDN references")


def main() -> None:
parser = argparse.ArgumentParser(
description="Download CDN assets referenced by generated JavaScript"
)
parser.add_argument("site_dir", nargs="?", default="site", type=Path)
args = parser.parse_args()
localize(args.site_dir.resolve())


if __name__ == "__main__":
main()
14 changes: 3 additions & 11 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ docs_dir: web/
theme:
font: false
name: material
variant: classic
logo: 'logo.svg'
favicon: 'favicon.ico'
palette:
Expand Down Expand Up @@ -33,14 +34,6 @@ theme:

custom_dir: overrides

plugins:
- search
- privacy
- redirects:
redirect_maps:
'wiki/JIT-Debugging.md': 'docs/jit-debugging.md'
'wiki/arm64.md': 'docs/arm64.md'

extra_css:
- 'stylesheets/extra.css'
- 'stylesheets/fonts.css'
Expand Down Expand Up @@ -94,8 +87,8 @@ markdown_extensions:
- pymdownx.critic
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
emoji_index: !!python/name:zensical.extensions.emoji.twemoji
emoji_generator: !!python/name:zensical.extensions.emoji.to_svg
- pymdownx.inlinehilite
- pymdownx.magiclink
- pymdownx.mark
Expand Down Expand Up @@ -185,4 +178,3 @@ nav:
- 'privacy.md'
- 'contact.md'
- 'codeofconduct.md'

8 changes: 4 additions & 4 deletions overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
{% endif %}
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ title }}" />
{%- if page.is_homepage %}
{% if page.meta and page.meta.description %}
<meta property="og:description" content="{{ page.meta.description }}" />
{% elif config.site_description %}
<meta property="og:description" content="{{ config.site_description }}" />
{% else %}{%- if page %}
<meta property="og:description" content="{{ page.meta.summary }}" />
{% endif %}{% endif %}
{% endif %}
<meta property="og:url" content="{{ page.canonical_url }}" />
<meta property="og:image" content="https://www.msys2.org/logo.png" />
<meta property="og:image:type" content="image/png" />
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ requires-python = ">=3.10,<4.0"

[dependency-groups]
dev = [
"properdocs>=1.6.7,<2",
"mkdocs-material>=9.5.0,<10",
"mkdocs-redirects>=1.2.2",
"zensical>=0.0.53,<0.1",
"beautifulsoup4>=4.13.4,<5",
]

Expand Down
Loading