11
11
from django .core .files .storage import get_storage_class
12
12
from django .db import models
13
13
from django .urls import NoReverseMatch , reverse
14
- from django .utils .functional import cached_property
15
14
from django .utils .translation import ugettext_lazy as _
16
15
from django_extensions .db .models import TimeStampedModel
17
16
from guardian .shortcuts import assign
@@ -1143,31 +1142,34 @@ class Meta(object):
1143
1142
1144
1143
objects = HTMLFileManager ()
1145
1144
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 = []
1148
1159
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' ):
1150
1162
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' )
1159
1164
1160
1165
full_json_path = self .project .get_production_media_path (
1161
1166
type_ = 'json' , version_slug = self .version .slug , include_file = False
1162
1167
)
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
1169
1168
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 )
1171
1173
except Exception :
1172
1174
log .warning (
1173
1175
'Unhandled exception during search processing file: %s' ,
@@ -1181,7 +1183,7 @@ def get_processed_json(self):
1181
1183
'sections' : [],
1182
1184
}
1183
1185
1184
- @cached_property
1186
+ @property
1185
1187
def processed_json (self ):
1186
1188
return self .get_processed_json ()
1187
1189
0 commit comments