afterpython 0.5.2__py3-none-any.whl → 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- afterpython/builders/seo.py +27 -0
- {afterpython-0.5.2.dist-info → afterpython-0.5.3.dist-info}/METADATA +1 -1
- {afterpython-0.5.2.dist-info → afterpython-0.5.3.dist-info}/RECORD +5 -5
- {afterpython-0.5.2.dist-info → afterpython-0.5.3.dist-info}/WHEEL +0 -0
- {afterpython-0.5.2.dist-info → afterpython-0.5.3.dist-info}/entry_points.txt +0 -0
afterpython/builders/seo.py
CHANGED
|
@@ -10,6 +10,9 @@ generator:
|
|
|
10
10
|
- internal links rewritten to that canonical form, so `/doc/quickstart` (301 on
|
|
11
11
|
GitHub Pages) becomes `/doc/quickstart/`
|
|
12
12
|
- `noindex` on the SPA fallback (200.html) and 404.html
|
|
13
|
+
- absolute `og:image`/`twitter:image` URLs, plus a large-image `twitter:card`
|
|
14
|
+
when missing, so link previews (X, Slack, LinkedIn) show the thumbnail:
|
|
15
|
+
crawlers ignore relative image paths like `/thumbnail.png`
|
|
13
16
|
- sitemap.xml listing every indexable page, plus a robots.txt pointing to it
|
|
14
17
|
"""
|
|
15
18
|
|
|
@@ -20,6 +23,7 @@ import posixpath
|
|
|
20
23
|
import re
|
|
21
24
|
from functools import partial
|
|
22
25
|
from pathlib import Path, PurePosixPath
|
|
26
|
+
from urllib.parse import urljoin
|
|
23
27
|
from xml.sax.saxutils import escape
|
|
24
28
|
|
|
25
29
|
import click
|
|
@@ -40,6 +44,13 @@ _META_REFRESH = re.compile(r"<meta[^>]*http-equiv=[\"']?refresh", re.IGNORECASE)
|
|
|
40
44
|
_HREF = re.compile(
|
|
41
45
|
r"""(\shref=)(["'])(?![a-zA-Z][\w+.-]*:|#)([^"']+)\2""", re.IGNORECASE
|
|
42
46
|
)
|
|
47
|
+
# content of an og:image / twitter:image meta tag (property/name before content,
|
|
48
|
+
# as both SvelteKit and MyST write it)
|
|
49
|
+
_SOCIAL_IMAGE = re.compile(
|
|
50
|
+
r"""(<meta[^>]*?(?:property|name)=["']?(?:og|twitter):image["']?[^>]*?\scontent=)(["'])([^"']+)\2""",
|
|
51
|
+
re.IGNORECASE,
|
|
52
|
+
)
|
|
53
|
+
_TWITTER_CARD = re.compile(r"<meta[^>]*name=[\"']?twitter:card", re.IGNORECASE)
|
|
43
54
|
|
|
44
55
|
|
|
45
56
|
def _canonical_path(rel: PurePosixPath) -> str:
|
|
@@ -109,6 +120,13 @@ def _rewrite_href(
|
|
|
109
120
|
return f"{prefix}{quote}{new_path}{sep}{rest}{quote}"
|
|
110
121
|
|
|
111
122
|
|
|
123
|
+
def _absolute_image(match: re.Match, page_url: str) -> str:
|
|
124
|
+
"""Resolve an og:image/twitter:image URL against the page's own URL."""
|
|
125
|
+
prefix, quote, url = match.group(1), match.group(2), match.group(3)
|
|
126
|
+
absolute = urljoin(page_url, html.unescape(url))
|
|
127
|
+
return f"{prefix}{quote}{html.escape(absolute)}{quote}"
|
|
128
|
+
|
|
129
|
+
|
|
112
130
|
def _split_url(url: str) -> tuple[str, str, str]:
|
|
113
131
|
"""Split '/a/b?x#y' into ('/a/b', '?', 'x#y')."""
|
|
114
132
|
for i, ch in enumerate(url):
|
|
@@ -173,6 +191,15 @@ def build_seo(base_path: str = ""):
|
|
|
173
191
|
),
|
|
174
192
|
text,
|
|
175
193
|
)
|
|
194
|
+
# link previews need absolute image URLs; already absolute ones pass through
|
|
195
|
+
page_url = site_root + base_path + page_path
|
|
196
|
+
text = _SOCIAL_IMAGE.sub(partial(_absolute_image, page_url=page_url), text)
|
|
197
|
+
# MyST pages only have og:image: without a card type X shows no image
|
|
198
|
+
head = _HEAD_OPEN.search(text)
|
|
199
|
+
if head and _SOCIAL_IMAGE.search(text) and not _TWITTER_CARD.search(text):
|
|
200
|
+
tag = '<meta name="twitter:card" content="summary_large_image">'
|
|
201
|
+
text = text[: head.end()] + tag + text[head.end() :]
|
|
202
|
+
|
|
176
203
|
# a shadowed x/index.html points at its x.html twin
|
|
177
204
|
canonical_url = (
|
|
178
205
|
site_root + base_path + canonical_by_path.get(page_path, page_path)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: afterpython
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.3
|
|
4
4
|
Summary: CLI tool to streamline Python package maintenance and generate a dedicated project website
|
|
5
5
|
Keywords: package-maintenance,project-website,static-site-generator,developer-tools,documentation,cli-tool,ci/cd,mystmd,semantic-release,python-packaging
|
|
6
6
|
Author: Stephen Yau
|
|
@@ -15,7 +15,7 @@ afterpython/builders/marimo_content.py,sha256=NEsvgomB8Dc90iirxsMMc2m0eXDemc05Pt
|
|
|
15
15
|
afterpython/builders/marimo_notebook.py,sha256=MwcXu5fz5Mvf3-SR_o6phw-UNwDz12IAH3txiM0yoeM,6662
|
|
16
16
|
afterpython/builders/markdown.py,sha256=0ExfRqvOTWsgUkAVaGGNkiNDtNedRr7JR1yTGxpbsmA,8736
|
|
17
17
|
afterpython/builders/metadata.py,sha256=ms17MJ4QD2PNtyDwQAPRTpFs-qBjT-1iKuIGUOjAseY,4042
|
|
18
|
-
afterpython/builders/seo.py,sha256=
|
|
18
|
+
afterpython/builders/seo.py,sha256=hzYDfnLSFPsbBJEJ8iPrSYqN-QNVzCn6IaB2BIjUrME,9867
|
|
19
19
|
afterpython/builders/site_data.py,sha256=29p2Hg1RBraZLd9l4jofvCq_QT43ny209-2TP5MDQBU,7133
|
|
20
20
|
afterpython/builders/url_md.py,sha256=MfXSy0f44J72OlHASir-Xscqq1onA10vtqUO_L4b1xM,3949
|
|
21
21
|
afterpython/cli/__init__.py,sha256=G4AB-rllhmr7tURFc5cXJfkjZZ2bXtMBg3oy4zUGEFw,84
|
|
@@ -69,7 +69,7 @@ afterpython/tools/prek.py,sha256=NEEGf8alTt9MIelAJ8yxWD-V4mnM_pJ7oHgVQG8pbzo,354
|
|
|
69
69
|
afterpython/tools/pyproject.py,sha256=Slhxo-Z9M7Gn9ZGL2BKmbPONpDgAJ1g33TdiulxwEyQ,3700
|
|
70
70
|
afterpython/utils.py,sha256=JyNFhanWllmuE3Ax5URi6_UxVgM9GsqgGwceg4PbFlo,12572
|
|
71
71
|
afterpython/version.py,sha256=hihRV1S-gc1m46OaXD32ikkEkqzs-Gtq7AcAqOQV-wY,1603
|
|
72
|
-
afterpython-0.5.
|
|
73
|
-
afterpython-0.5.
|
|
74
|
-
afterpython-0.5.
|
|
75
|
-
afterpython-0.5.
|
|
72
|
+
afterpython-0.5.3.dist-info/WHEEL,sha256=MWx7psoF7KNST9G72pGtiBYuaXRXQXBk9pw5R6FzYko,80
|
|
73
|
+
afterpython-0.5.3.dist-info/entry_points.txt,sha256=roa0PDgBueM1JPbRG0G2OSxzaN394OUL_oS9iEwVLBc,80
|
|
74
|
+
afterpython-0.5.3.dist-info/METADATA,sha256=J_c3RAhPFkLnpdwhCSCGM6qDHO78Ex0u5Lcn_ODUSP4,6416
|
|
75
|
+
afterpython-0.5.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|