Skip to content

Commit

Permalink
Check for two paths for each file
Browse files Browse the repository at this point in the history
This is because HTMLDir can generate a file from two different places:

* foo.rst
* foo/index.rst

Both lead to `foo/index.html`

refs #5368
  • Loading branch information
ericholscher committed Feb 27, 2019
1 parent 439e8af commit 5cc3587
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,31 +1143,35 @@ class Meta(object):

objects = HTMLFileManager()

@cached_property
def json_file_path(self):

def get_processed_json(self):
"""
Check for two paths for each file
This is because HTMLDir can generate a file from two different places:
* foo.rst
* foo/index.rst
Both lead to `foo/index.html`
https://github.com/rtfd/readthedocs.org/issues/5368
"""
paths = []
basename = os.path.splitext(self.path)[0]
if self.project.documentation_type == 'sphinx_htmldir' and basename.endswith('/index'):
paths.append(basename + '.fjson')
if basename.endswith('/index'):
new_basename = re.sub(r'\/index$', '', basename)
log.info(
'Adjusted json file path: %s -> %s',
basename,
new_basename,
)
basename = new_basename

file_path = basename + '.fjson'
paths.append(new_basename + '.fjson')

full_json_path = self.project.get_production_media_path(
type_='json', version_slug=self.version.slug, include_file=False
)

file_path = os.path.join(full_json_path, file_path)
return file_path

def get_processed_json(self):
file_path = self.json_file_path
try:
return process_file(file_path)
for path in paths:
file_path = os.path.join(full_json_path, path)
if os.path.exists(file_path):
return process_file(file_path)
except Exception:
log.warning(
'Unhandled exception during search processing file: %s',
Expand All @@ -1181,7 +1185,6 @@ def get_processed_json(self):
'sections': [],
}

@cached_property
def processed_json(self):
return self.get_processed_json()

Expand Down

0 comments on commit 5cc3587

Please sign in to comment.