Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop generating JSON data #126

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions readthedocs_ext/readthedocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,6 @@
'readthedocsdirhtml',
'readthedocssinglehtml',
]
# Only run JSON output once during HTML build
# This saves resources and keeps filepaths correct,
# because singlehtml filepaths are different
JSON_BUILDERS = [
'html',
'dirhtml',
'readthedocs',
'readthedocsdirhtml',
]

# Whitelist keys that we want to output
# to the json artifacts.
JSON_KEYS = [
'body',
'title',
'sourcename',
'current_page_name',
'toc',
'page_source_suffix',
]


def update_body(app, pagename, templatename, context, doctree):
Expand Down Expand Up @@ -194,44 +174,6 @@ def rtd_render(self, template, render_context):
app.builder.templates)


def generate_json_artifacts(app, pagename, templatename, context, doctree):
"""
Generate JSON artifacts for each page.

This way we can skip generating this in other build step.
"""
if app.builder.name not in JSON_BUILDERS:
return
try:
# We need to get the output directory where the docs are built
# _build/json.
build_json = os.path.abspath(
os.path.join(app.outdir, '..', 'json')
)
outjson = os.path.join(build_json, pagename + '.fjson')
outdir = os.path.dirname(outjson)
if not os.path.exists(outdir):
os.makedirs(outdir)
with open(outjson, 'w+') as json_file:
to_context = {
key: context.get(key, '')
for key in JSON_KEYS
}
json.dump(to_context, json_file, indent=4)
except TypeError:
log.exception(
'Fail to encode JSON for page {page}'.format(page=outjson)
)
except IOError:
log.exception(
'Fail to save JSON output for page {page}'.format(page=outjson)
)
except Exception:
log.exception(
'Failure in JSON search dump for page {page}'.format(page=outjson)
)


def remove_search_init(app, exception):
"""
Remove Sphinx's Search.init() so it can be initialized by Read the Docs.
Expand Down Expand Up @@ -350,7 +292,6 @@ class ReadtheDocsSingleFileHTMLBuilderLocalMedia(SingleFileHTMLBuilder):
def setup(app):
app.add_builder(ReadtheDocsSingleFileHTMLBuilderLocalMedia)
app.connect('html-page-context', update_body)
app.connect('html-page-context', generate_json_artifacts)
app.connect('build-finished', remove_search_init)

if sphinx.version_info >= (1, 8, 0):
Expand Down