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

Correctly report mkdocs theme name #3920

Merged
merged 4 commits into from
Apr 18, 2018
Merged
Changes from 2 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
8 changes: 5 additions & 3 deletions readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def append_conf(self, **__):
if 'theme_dir' not in user_config and self.use_theme:
user_config['theme_dir'] = TEMPLATE_DIR

user_config['theme_name'] = user_config.get('theme_dir', 'readthedocs').rsplit('/')[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually want to set this here? This will change what we're writing to the users config, which seems like we don't want to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This user_config comes from their mkdocs.yml file. The only place it is written is to the READTHEDOCS_DATA variable in the docs. I believe we do in fact want to know if people are using mkdocs with a different theme.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dump the mkdocs.yml back out below though, so this variable will exist in the mkdocs.yml we use to build the users project. Will having this unknown YAML key not mess with stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't fully realize what you meant. Ya, this should probably happen after the mkdocs.yml is written...


yaml.safe_dump(
user_config,
open(os.path.join(self.root_path, 'mkdocs.yml'), 'w')
Expand All @@ -108,11 +110,11 @@ def append_conf(self, **__):
docs_path = os.path.join(self.root_path, docs_dir)

# RTD javascript writing
rtd_data = self.generate_rtd_data(docs_dir=docs_dir)
rtd_data = self.generate_rtd_data(docs_dir=docs_dir, user_config=user_config)
with open(os.path.join(docs_path, 'readthedocs-data.js'), 'w') as f:
f.write(rtd_data)

def generate_rtd_data(self, docs_dir):
def generate_rtd_data(self, docs_dir, user_config):
"""Generate template properties and render readthedocs-data.js."""
# Will be available in the JavaScript as READTHEDOCS_DATA.
readthedocs_data = {
Expand All @@ -121,7 +123,7 @@ def generate_rtd_data(self, docs_dir):
'language': self.version.project.language,
'programming_language': self.version.project.programming_language,
'page': None,
'theme': "readthedocs",
'theme': user_config['theme_name'],
'builder': "mkdocs",
'docroot': docs_dir,
'source_suffix': ".md",
Expand Down