Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit946b6bc

Browse files
authored
Account for recent removal of self-closing tags (#264)
1 parente80b729 commit946b6bc

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

‎build_docs.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,25 +1265,26 @@ def proofread_canonicals(
12651265
purge(http,*paths_to_purge)
12661266

12671267

1268+
# Python 3.12 onwards doesn't use self-closing tags for <link rel="canonical">
1269+
_canonical_re=re.compile(
1270+
b"""<link rel="canonical" href="https://docs.python.org/([^"]*)"(?: /)?>"""
1271+
)
1272+
1273+
12681274
def_check_canonical_rel(file:Path,www_root:Path):
12691275
# Check for a canonical relation link in the HTML.
12701276
# If one exists, ensure that the target exists
12711277
# or otherwise remove the canonical link element.
1272-
prefix=b'<link rel="canonical" href="https://docs.python.org/'
1273-
suffix=b'" />'
1274-
pfx_len=len(prefix)
1275-
sfx_len=len(suffix)
12761278
html=file.read_bytes()
1277-
try:
1278-
start=html.index(prefix)
1279-
end=html.index(suffix,start+pfx_len)
1280-
exceptValueError:
1279+
canonical=_canonical_re.search(html)
1280+
ifcanonicalisNone:
12811281
returnNone
1282-
target=html[start+pfx_len :end].decode(errors="surrogateescape")
1282+
target=canonical[1].decode(encoding="UTF-8",errors="surrogateescape")
12831283
if (www_root/target).exists():
12841284
returnNone
12851285
logging.info("Removing broken canonical from %s to %s",file,target)
1286-
file.write_bytes(html[:start]+html[end+sfx_len :])
1286+
start,end=canonical.span()
1287+
file.write_bytes(html[:start]+html[end:])
12871288
returnfile
12881289

12891290

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp