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

Commit76cdfb2

Browse files
committed
Start a sitemap and a robots.txt.
1 parentc23b401 commit76cdfb2

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

‎build_docs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
importsys
4949
fromdatetimeimportdatetime
5050

51+
importjinja2
52+
5153
HERE=Path(__file__).resolve().parent
5254

5355
try:
@@ -80,6 +82,10 @@ def __init__(self, name, branch, status, sphinx_version=DEFAULT_SPHINX_VERSION):
8082
self.status=status
8183
self.sphinx_version=sphinx_version
8284

85+
@property
86+
defchangefreq(self):
87+
return {"EOL":"never","security-fixes":"yearly"}.get(self.status,"daily")
88+
8389
@property
8490
defurl(self):
8591
return"https://docs.python.org/{}/".format(self.name)
@@ -484,6 +490,22 @@ def build_venv(build_root, version):
484490
returnvenv_path
485491

486492

493+
defbuild_robots_txt(www_root):
494+
withopen(HERE/"templates"/"robots.txt")asrobots_txt_template_file:
495+
withopen(os.path.join(www_root,"robots.txt"),"w")asrobots_txt_file:
496+
template=jinja2.Template(robots_txt_template_file.read())
497+
robots_txt_file.write(
498+
template.render(languages=LANGUAGES,versions=VERSIONS)
499+
)
500+
501+
502+
defbuild_sitemap(www_root):
503+
withopen(HERE/"templates"/"sitemap.xml")assitemap_template_file:
504+
withopen(os.path.join(www_root,"sitemap.xml"),"w")assitemap_file:
505+
template=jinja2.Template(sitemap_template_file.read())
506+
sitemap_file.write(template.render(languages=LANGUAGES,versions=VERSIONS))
507+
508+
487509
defcopy_build_to_webroot(
488510
build_root,
489511
version,
@@ -768,6 +790,8 @@ def main():
768790
)
769791
ifsentry_sdk:
770792
sentry_sdk.capture_exception(err)
793+
build_sitemap(args.www_root)
794+
build_robots_txt(args.www_root)
771795

772796

773797
if__name__=="__main__":

‎requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
sentry-sdk
2+
jinja2

‎templates/robots.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Sitemap:https://docs.python.org/sitemap.xml
2+
3+
# Prevent development and old documentation from showing up in search results.
4+
User-agent:*
5+
Disallow:/dev
6+
Disallow:/release
7+
8+
# Disallow EOL versions
9+
Disallow:/2/
10+
Disallow:/2.0/
11+
Disallow:/2.1/
12+
Disallow:/2.2/
13+
Disallow:/2.3/
14+
Disallow:/2.4/
15+
Disallow:/2.5/
16+
Disallow:/2.6/
17+
Disallow:/2.7/
18+
Disallow:/3.0/
19+
Disallow:/3.1/
20+
Disallow:/3.2/
21+
Disallow:/3.3/
22+
Disallow:/3.4/

‎templates/sitemap.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlsetxmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
3+
xmlns:xhtml="http://www.w3.org/1999/xhtml">
4+
{% for version in versions %}
5+
<url>
6+
<loc>https://docs.python.org/{{ version.name }}/</loc>
7+
{% for language in languages -%}
8+
<xhtml:linkrel="alternate"hreflang="{{ language.iso639_tag.replace('_', '-') }}"href="https://docs.python.org/{{ language.tag }}/{{ version.name }}/"/>
9+
{% endfor -%}
10+
<changefreq>{{ version.changefreq }}</changefreq>
11+
</url>
12+
{% endfor %}
13+
<url>
14+
<loc>https://docs.python.org/3/</loc>
15+
{% for language in languages -%}
16+
<xhtml:linkrel="alternate"hreflang="{{ language.iso639_tag.replace('_', '-') }}"href="https://docs.python.org/{{ language.tag }}/3/"/>
17+
{% endfor -%}
18+
<changefreq>daily}</changefreq>
19+
</url>
20+
21+
<url>
22+
<loc>https://docs.python.org/dev/</loc>
23+
{% for language in languages -%}
24+
<xhtml:linkrel="alternate"hreflang="{{ language.iso639_tag.replace('_', '-') }}"href="https://docs.python.org/{{ language.tag }}/dev/"/>
25+
{% endfor -%}
26+
<changefreq>daily</changefreq>
27+
</url>
28+
</urlset>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp