Skip to content

Commit df4c75a

Browse files
committed
Merge pull request astropy#7909 from dasdachs/add-robots-txt
Removed robots.txt and added an extension to layout.html
1 parent fa8f16f commit df4c75a

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

docs/_templates/layout.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{# This extension of the 'layout.html' prevents documentation for previous
2+
versions of Astropy to be indexed by bots, e.g. googlebot or bing bot,
3+
by inserting a robots meta tag into pages that are not in the stable or
4+
latest branch.
5+
6+
It assumes that the documentation is built by and hosted on readthedocs.org:
7+
1. Readthedocs.org has a global robots.txt and no option for a custom one.
8+
2. The readthedocs app passes additional variables to the template context,
9+
one of them being `version_slug`. This variable is a string computed from
10+
the tags of the branches that are selected to be built. It can be 'latest',
11+
'stable' or even a unique stringified version number.
12+
13+
For more information, please refer to:
14+
https://github.com/astropy/astropy/pull/7874
15+
http://www.robotstxt.org/meta.html
16+
https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/builds/version_slug.py
17+
#}
18+
19+
{% extends "!layout.html" %}
20+
{%- block extrahead %}
21+
{% if not version_slug in to_be_indexed %}
22+
<meta name="robots" content="noindex, nofollow">
23+
{% endif %}
24+
{{ super() }}
25+
{% endblock %}

docs/conf.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@
173173
# Output file base name for HTML help builder.
174174
htmlhelp_basename = project + 'doc'
175175

176+
# A dictionary of values to pass into the template engine’s context for all pages.
177+
html_context = {
178+
'to_be_indexed': ['stable', 'latest']
179+
}
176180

177181
# -- Options for LaTeX output --------------------------------------------------
178182

@@ -252,8 +256,3 @@ def setup(app):
252256
'to this.')
253257

254258
linkcheck_anchors = False
255-
256-
# Add any extra paths that contain custom files (such as robots.txt or
257-
# .htaccess) here, relative to this directory. These files are copied
258-
# directly to the root of the documentation.
259-
html_extra_path = ['robots.txt']

docs/robots.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)