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

Account for recent removal of self-closing tags#264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
AA-Turner merged 1 commit intomainfromcanonicals
Apr 11, 2025
Merged
Changes fromall 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
21 changes: 11 additions & 10 deletionsbuild_docs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1265,25 +1265,26 @@ def proofread_canonicals(
purge(http, *paths_to_purge)


# Python 3.12 onwards doesn't use self-closing tags for <link rel="canonical">
_canonical_re = re.compile(
b"""<link rel="canonical" href="https://docs.python.org/([^"]*)"(?: /)?>"""
)


def _check_canonical_rel(file: Path, www_root: Path):
# Check for a canonical relation link in the HTML.
# If one exists, ensure that the target exists
# or otherwise remove the canonical link element.
prefix = b'<link rel="canonical" href="https://docs.python.org/'
suffix = b'" />'
pfx_len = len(prefix)
sfx_len = len(suffix)
html = file.read_bytes()
try:
start = html.index(prefix)
end = html.index(suffix, start + pfx_len)
except ValueError:
canonical = _canonical_re.search(html)
if canonical is None:
return None
target =html[start + pfx_len : end].decode(errors="surrogateescape")
target =canonical[1].decode(encoding="UTF-8",errors="surrogateescape")
if (www_root / target).exists():
return None
logging.info("Removing broken canonical from %s to %s", file, target)
file.write_bytes(html[:start] + html[end + sfx_len :])
start, end = canonical.span()
file.write_bytes(html[:start] + html[end:])
return file


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp