-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Support redirects from non-padded PEP numbers #2421
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||
{# 404 Not Found: Redirect typos and link to PEP 0 #} | ||||||
<!DOCTYPE html> | ||||||
<html lang="en"> | ||||||
<head> | ||||||
<meta charset="utf-8" /> | ||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||||||
<meta name="color-scheme" content="light dark" /> | ||||||
<title>PEP Not Found | peps.python.org</title> | ||||||
<link rel="shortcut icon" href="{{ pathto('_static/py.png', resource=True) }}"/> | ||||||
<link rel="stylesheet" href="{{ pathto('_static/style.css', resource=True) }}" type="text/css" /> | ||||||
<link rel="stylesheet" href="{{ pathto('_static/mq.css', resource=True) }}" type="text/css" /> | ||||||
<link rel="stylesheet" href="{{ pathto('_static/dark.css', resource=True) }}" type="text/css" media="(prefers-color-scheme: dark)" id="css-dark"/> | ||||||
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet"> | ||||||
<meta name="description" content="Python Enhancement Proposals (PEPs)"/> | ||||||
<script> | ||||||
const pepNumMatch = window.location.pathname.match(/^\d+$/) | ||||||
if (pepNumMatch !== null) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our comments crossed over, sorry!
A |
||||||
const pepNum = pepNumMatch[0] | ||||||
window.location.pathname = "/pep-" + pepNum.padStart(4, "0") | ||||||
} | ||||||
</script> | ||||||
</head> | ||||||
<body> | ||||||
<section id="pep-page-section"> | ||||||
<header> | ||||||
<h1>Python Enhancement Proposals</h1> | ||||||
<ul class="breadcrumbs"> | ||||||
<li><a href="https://www.python.org/" title="The Python Programming Language">Python</a> » </li> | ||||||
<li><a href="{{ pathto("pep-0000") }}">PEP Index</a></li> | ||||||
ezio-melotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
</ul> | ||||||
<button onClick="toggleColourScheme()"></button> | ||||||
</header> | ||||||
<article> | ||||||
<section id="pep-content"> | ||||||
<h1 class="page-title">PEP Not Found</h1> | ||||||
<p>There is no PEP at this address.</p> | ||||||
<p>Please return to <a href="{{ pathto("pep-0000") }}">the index</a>.</p> | ||||||
</section> | ||||||
</article> | ||||||
<nav id="pep-sidebar"></nav> | ||||||
</section> | ||||||
<script src="{{ pathto('_static/colour_scheme.js', resource=True) }}"></script> | ||||||
</body> | ||||||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
^
and$
in the regex, it won't matchpep-NNN
. Did you just change this temporarily to test?Note that in the suggestion below I used
match[0]
because of this change, but if my previous suggestion is restored it should bematch[1]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From above, "I don't want to include the
pep-
prefix for the auto-redirects"A
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
If we set the autolinking to
https://peps.python.org/pep-<num>/
and<num>
is a valid 4-digits number (e.g. pep-0008), then it will go straight to the right page. If we omit thepep-
prefix, then it will have to go through an extra redirect if JS is enabled, or end up at the 404 page if JS is disabled.In case of a valid PEP with a <4 digits number (e.g. pep-8) it will go to
/pep-8/
and get redirected to/pep-0008
.In case of an invalid PEP with a <4 digits number (e.g. pep-123) it will go to
/pep-123/
, get redirected to/pep-0123
, and then stop at the 404 page since the PEP doesn't exist and the id is already 4 digits long.Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autolinking on this repo is currently set to link to
https://python.org/dev/peps/pep-<num>
. My suggestion that simply matchedpep-(\d+)
works even with this type of URL, but fails with/^\d+$/
.