Skip to content

Commit bdacceb

Browse files
authored
Merge pull request #5370 from rtfd/fix-htmldir-search-index
Check for two paths for each file
2 parents 5957184 + 124cb86 commit bdacceb

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

readthedocs/projects/models.py

+22-20
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from django.core.files.storage import get_storage_class
1212
from django.db import models
1313
from django.urls import NoReverseMatch, reverse
14-
from django.utils.functional import cached_property
1514
from django.utils.translation import ugettext_lazy as _
1615
from django_extensions.db.models import TimeStampedModel
1716
from guardian.shortcuts import assign
@@ -1143,31 +1142,34 @@ class Meta(object):
11431142

11441143
objects = HTMLFileManager()
11451144

1146-
@cached_property
1147-
def json_file_path(self):
1145+
def get_processed_json(self):
1146+
"""
1147+
Get the parsed JSON for search indexing.
1148+
1149+
Check for two paths for each index file
1150+
This is because HTMLDir can generate a file from two different places:
1151+
1152+
* foo.rst
1153+
* foo/index.rst
1154+
1155+
Both lead to `foo/index.html`
1156+
https://github.com/rtfd/readthedocs.org/issues/5368
1157+
"""
1158+
paths = []
11481159
basename = os.path.splitext(self.path)[0]
1149-
if self.project.documentation_type == 'sphinx_htmldir' and basename.endswith('/index'):
1160+
paths.append(basename + '.fjson')
1161+
if basename.endswith('/index'):
11501162
new_basename = re.sub(r'\/index$', '', basename)
1151-
log.info(
1152-
'Adjusted json file path: %s -> %s',
1153-
basename,
1154-
new_basename,
1155-
)
1156-
basename = new_basename
1157-
1158-
file_path = basename + '.fjson'
1163+
paths.append(new_basename + '.fjson')
11591164

11601165
full_json_path = self.project.get_production_media_path(
11611166
type_='json', version_slug=self.version.slug, include_file=False
11621167
)
1163-
1164-
file_path = os.path.join(full_json_path, file_path)
1165-
return file_path
1166-
1167-
def get_processed_json(self):
1168-
file_path = self.json_file_path
11691168
try:
1170-
return process_file(file_path)
1169+
for path in paths:
1170+
file_path = os.path.join(full_json_path, path)
1171+
if os.path.exists(file_path):
1172+
return process_file(file_path)
11711173
except Exception:
11721174
log.warning(
11731175
'Unhandled exception during search processing file: %s',
@@ -1181,7 +1183,7 @@ def get_processed_json(self):
11811183
'sections': [],
11821184
}
11831185

1184-
@cached_property
1186+
@property
11851187
def processed_json(self):
11861188
return self.get_processed_json()
11871189

0 commit comments

Comments
 (0)