Skip to content

Commit 88f58bf

Browse files
committed
Proxito: browndate for redirecting / to README.html
Related #9993
1 parent 266ea25 commit 88f58bf

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

readthedocs/projects/tasks/search.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from readthedocs.builds.models import Build, Version
77
from readthedocs.projects.models import HTMLFile, Project
88
from readthedocs.projects.signals import files_changed
9+
from readthedocs.proxito.views.utils import allow_readme_html_at_root_url
910
from readthedocs.search.documents import PageDocument
1011
from readthedocs.search.utils import index_objects, remove_indexed_files
1112
from readthedocs.storage import build_media_storage
@@ -203,7 +204,12 @@ def _create_imported_files_and_search_index(
203204

204205
# Create the imported file only if it's a top-level 404 file,
205206
# or if it's an index file. We don't need to keep track of all files.
206-
if relpath == "404.html" or filename in ["index.html", "README.html"]:
207+
if allow_readme_html_at_root_url():
208+
tryfiles = ["index.html", "README.html"]
209+
else:
210+
tryfiles = ["index.html"]
211+
212+
if relpath == "404.html" or filename in tryfiles:
207213
html_files_to_save.append(html_file)
208214

209215
# We first index the files in ES, and then save the objects in the DB.

readthedocs/proxito/views/serve.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ServeRedirectMixin,
4242
StorageFileNotFound,
4343
)
44+
from readthedocs.proxito.views.utils import allow_readme_html_at_root_url
4445
from readthedocs.redirects.exceptions import InfiniteRedirectException
4546
from readthedocs.storage import build_media_storage
4647

@@ -641,12 +642,16 @@ def _get_index_file_redirect(self, request, project, version, filename, full_pat
641642
- /en/latest/foo -> /en/latest/foo/README.html
642643
- /en/latest/foo/ -> /en/latest/foo/README.html
643644
"""
644-
tryfiles = ["index.html", "README.html"]
645-
# If the path ends with `/`, we already tried to serve
646-
# the `/index.html` file, so we only need to test for
647-
# the `/README.html` file.
648-
if full_path.endswith("/"):
649-
tryfiles = ["README.html"]
645+
646+
if allow_readme_html_at_root_url():
647+
tryfiles = ["index.html", "README.html"]
648+
# If the path ends with `/`, we already tried to serve
649+
# the `/index.html` file, so we only need to test for
650+
# the `/README.html` file.
651+
if full_path.endswith("/"):
652+
tryfiles = ["README.html"]
653+
else:
654+
tryfiles = ["index.html"]
650655

651656
tryfiles = [
652657
(filename.rstrip("/") + f"/{tryfile}").lstrip("/") for tryfile in tryfiles
@@ -664,7 +669,7 @@ def _get_index_file_redirect(self, request, project, version, filename, full_pat
664669
log.info("Redirecting to index file.", tryfile=tryfile)
665670
# Use urlparse so that we maintain GET args in our redirect
666671
parts = urlparse(full_path)
667-
if tryfile.endswith("README.html"):
672+
if allow_readme_html_at_root_url() and tryfile.endswith("README.html"):
668673
new_path = parts.path.rstrip("/") + "/README.html"
669674
else:
670675
new_path = parts.path.rstrip("/") + "/"

readthedocs/proxito/views/utils.py

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import datetime
2+
3+
import pytz
14
import structlog
5+
from django.conf import settings
26
from django.http import HttpResponse
37
from django.shortcuts import render
48

@@ -56,3 +60,22 @@ def proxito_404_page_handler(
5660
)
5761
r.status_code = http_status
5862
return r
63+
64+
65+
def allow_readme_html_at_root_url():
66+
tzinfo = pytz.timezone("America/Los_Angeles")
67+
now = datetime.datetime.now(tz=tzinfo)
68+
69+
# Brownout dates as published in https://about.readthedocs.com/blog/2024/05/readme-html-deprecated/
70+
# fmt: off
71+
return not any([
72+
# 12 hours browndate
73+
datetime.datetime(2024, 6, 10, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 6, 10, 12, 0, 0, tzinfo=tzinfo),
74+
# 24 hours browndate
75+
datetime.datetime(2024, 6, 17, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 6, 18, 0, 0, 0, tzinfo=tzinfo),
76+
# 48 hours browndate
77+
datetime.datetime(2024, 6, 24, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 6, 26, 0, 0, 0, tzinfo=tzinfo),
78+
# Deprecated after July 1st
79+
datetime.datetime(2024, 7, 1, 0, 0, 0, tzinfo=tzinfo) < now,
80+
]) and settings.RTD_ENFORCE_BROWNOUTS_FOR_DEPRECATIONS
81+
# fmt: on

0 commit comments

Comments
 (0)