Skip to content

Commit

Permalink
Merge pull request #569 from bmorris3/docs-version-fix
Browse files Browse the repository at this point in the history
Docs revisions
  • Loading branch information
bmorris3 authored Sep 20, 2023
2 parents 258a88c + 39e7739 commit 4562c8e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
25 changes: 25 additions & 0 deletions docs/_templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{# This extension of the 'layout.html' prevents documentation for previous
versions of Astropy to be indexed by bots, e.g. googlebot or bing bot,
by inserting a robots meta tag into pages that are not in the stable or
latest branch.

It assumes that the documentation is built by and hosted on readthedocs.org:
1. Readthedocs.org has a global robots.txt and no option for a custom one.
2. The readthedocs app passes additional variables to the template context,
one of them being `version_slug`. This variable is a string computed from
the tags of the branches that are selected to be built. It can be 'latest',
'stable' or even a unique stringified version number.

For more information, please refer to:
https://github.com/astropy/astropy/pull/7874
http://www.robotstxt.org/meta.html
https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/builds/version_slug.py
#}

{% extends "!layout.html" %}
{%- block extrahead %}
{% if not version_slug in to_be_indexed %}
<meta name="robots" content="noindex, nofollow">
{% endif %}
{{ super() }}
{% endblock %}
23 changes: 16 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See astropy.sphinx.conf for which values are set there.

from configparser import ConfigParser
from astroplan import __version__
import sys
import datetime
from importlib import metadata

try:
from sphinx_astropy.conf.v2 import * # noqa
Expand Down Expand Up @@ -70,10 +70,17 @@
__import__(project)
package = sys.modules[project]

# The short X.Y version.
version = package.__version__.split('-', 1)[0]
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.

# The full version, including alpha/beta/rc tags.
release = package.__version__
release = metadata.version(project)
# The short X.Y version.
version = ".".join(release.split(".")[:2])

# Only include dev docs in dev version.
dev = "dev" in release


# -- Options for HTML output ---------------------------------------------------
Expand Down Expand Up @@ -173,9 +180,6 @@
# -- Turn on nitpicky mode for sphinx (to warn about references not found) ----
nitpicky = True

release = __version__
dev = "dev" in release

html_copy_source = False

html_theme_options.update( # noqa: F405
Expand All @@ -198,6 +202,11 @@
"doc_path": "docs",
}

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
html_extra_path = ["robots.txt"]

#
# Some warnings are impossible to suppress, and you can list specific references
# that should be ignored in a nitpick-exceptions file which should be inside
Expand Down
11 changes: 3 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ License: BSD-3

.. _astroplan_docs:

General Documentation
=====================
Documentation
=============

.. toctree::
:maxdepth: 2
Expand All @@ -44,13 +44,8 @@ General Documentation
api
changelog

.. _astroplan_authors:

Authors
=======

Maintainers
-----------
+++++++++++
* `Brett Morris, including contributions from Google Summer of Code 2015 <https://www.google-melange.com/gsoc/project/details/google/gsoc2015/bmmorris/5707702298738688>`_

Attribution
Expand Down
6 changes: 6 additions & 0 deletions docs/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
User-agent: *
Allow: /*/latest/
Allow: /en/latest/ # Fallback for bots that don't understand wildcards
Allow: /*/stable/
Allow: /en/stable/ # Fallback for bots that don't understand wildcards
Disallow: /

0 comments on commit 4562c8e

Please sign in to comment.