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

Commit1ff05eb

Browse files
committed
Minor stylistic changes to redirects script.
1 parent2f144a8 commit1ff05eb

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

‎_websiteutils/make_redirects_links.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
found of the html file (including stable if its in the latest version.)
2323
2424
Third, the script adds a new div to the top of all the old webpages with
25-
tag ``olddocs-message`` to warn users that the page is obsolete.
25+
tag ``olddocs-message`` to warn users that the page is obsolete.
2626
2727
This script takes a while, and is destructive, so should probably be run on a
2828
branch and pushed as a PR so it can easily be reverted.
@@ -73,17 +73,16 @@ def findlast(fname, tocheck, *, _cache={}):
7373
returnNone
7474

7575

76-
html_redirect="""
77-
<!DOCTYPE HTML>
76+
html_redirect="""<!DOCTYPE HTML>
7877
<html lang="en">
7978
<head>
8079
<meta charset="utf-8">
81-
<meta http-equiv="refresh" content="0;url=%s" />
82-
<link rel="canonical" href="https://matplotlib.org%s" />
80+
<meta http-equiv="refresh" content="0;url={newurl}" />
81+
<link rel="canonical" href="https://matplotlib.org/{canonical}" />
8382
</head>
8483
<body>
8584
<h1>
86-
The page been moved <a href="%s">here</a>!
85+
The page been moved <a href="{newurl}">here</a>!
8786
</h1>
8887
</body>
8988
</html>
@@ -92,14 +91,14 @@ def findlast(fname, tocheck, *, _cache={}):
9291
# note these are all one line so they are easy to search and replace in the
9392
# html files (otherwise we need to close tags)
9493
warn_banner_exists= (
95-
'<div> You are reading an old version of the'
96-
'documentation (v%s). For the latest version see '
97-
'<a href="%s">%s</a></div>\n')
94+
'<div> You are reading an old version of the'
95+
'documentation (v{version}). For the latest version see '
96+
'<a href="{url}">{url}</a></div>\n')
9897

9998

10099
warn_banner_old= (
101-
'<div> You are reading an old version of the'
102-
'documentation (v%s). For the latest version see '
100+
'<div> You are reading an old version of the'
101+
'documentation (v{version}). For the latest version see '
103102
'<a href="/stable/">https://matplotlib.org/stable/</a> </div>\n')
104103

105104

@@ -123,10 +122,9 @@ def do_links(root0):
123122
_log.info(f"Rewriting HTML:{fullname} in{last}")
124123
withopen(fullname,"w")asfout:
125124
oldname=os.path.join(last,fullname)
126-
st=html_redirect% (
127-
"../"* (depth+1)+oldname,
128-
"/"+oldname,
129-
"../"* (depth+1)+oldname,
125+
st=html_redirect.format(
126+
newurl="../"* (depth+1)+oldname,
127+
canonical=oldname,
130128
)
131129
fout.write(st)
132130
else:
@@ -191,10 +189,10 @@ def update_canonical(fullname, last, newest):
191189
fout.write(line)
192190
line=next(fin)
193191
iflast=='stable':
194-
new=warn_banner_exists% (p.parts[0],newcanon,
195-
newcanon)
192+
new=warn_banner_exists.format(version=p.parts[0],
193+
url=newcanon)
196194
else:
197-
new=warn_banner_old% (p.parts[0])
195+
new=warn_banner_old.format(version=p.parts[0])
198196
fout.write(new.encode("utf-8"))
199197
ifb'<div id="olddocs-message">'notinline:
200198
# write the line out if it wasn't an olddocs-message:
@@ -208,12 +206,12 @@ def update_canonical(fullname, last, newest):
208206

209207
if__name__=="__main__":
210208

211-
parser=argparse.ArgumentParser(description="Optional app description")
209+
parser=argparse.ArgumentParser()
212210

213211
parser.add_argument("--np",type=int,help="Number of processors to use")
214-
parser.add_argument("--no_canonicals",help="do not do canonical links",
212+
parser.add_argument("--no-canonicals",help="do not do canonical links",
215213
action="store_true")
216-
parser.add_argument("--no_redirects",help="do not do redirects links",
214+
parser.add_argument("--no-redirects",help="do not do redirects links",
217215
action="store_true")
218216

219217
args=parser.parse_args()
@@ -229,21 +227,21 @@ def update_canonical(fullname, last, newest):
229227
# html redirect or soft link most things in the top-level directory that
230228
# are not other modules or versioned docs.
231229
ifnotargs.no_redirects:
232-
forentryinos.scandir("./"):
233-
ifnot (entry.nameintoignore):
230+
forentryinos.scandir("."):
231+
ifentry.namenotintoignore:
234232
ifentry.is_dir():
235233
do_links(entry.name)
236234
elifentry.name.endswith((".htm",".html")):
237235
fullname=entry.name
238236
last=findlast(fullname,tocheck)
239237
_log.debug(f"Checking:{fullname} found{last}")
240238
iflastisnotNone:
241-
os.remove("./"+fullname)
239+
os.remove(fullname)
242240
_log.info(f"Rewriting HTML:{fullname} in{last}")
243241
withopen(fullname,"w")asfout:
244242
oldname=os.path.join(last,fullname)
245-
st=html_redirect% (oldname,"/"+oldname,
246-
oldname)
243+
st=html_redirect.format(newurl=oldname,
244+
canonical=oldname)
247245
fout.write(st)
248246
_log.info("Done links and redirects")
249247

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp