-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Updates and simplification for mkdocs #4556
Changes from 1 commit
a30768d
2d446c7
171ce95
4d82d8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,17 +39,8 @@ class BaseMkdocs(BaseBuilder): | |
|
||
"""Mkdocs builder.""" | ||
|
||
use_theme = True | ||
|
||
# The default theme for mkdocs (outside of RTD) is the 'mkdocs' theme | ||
# For RTD, our default is the 'readthedocs' theme | ||
READTHEDOCS_THEME_NAME = 'readthedocs' | ||
|
||
# Overrides for the 'readthedocs' theme that include | ||
# search utilities and version selector | ||
READTHEDOCS_TEMPLATE_OVERRIDE_DIR = ( | ||
'%s/readthedocs/templates/mkdocs/readthedocs' % settings.SITE_ROOT | ||
) | ||
# The default theme for mkdocs is the 'mkdocs' theme | ||
DEFAULT_THEME_NAME = 'mkdocs' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not default to the rtd theme when users don't have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Starting with mkdocs>=1.0, theme is required. Also, this is another source of confusion where Read the Docs does something different than the default MkDocs functionality. I believe we shouldn't be changing users' intents. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that makes sense, I wonder if this is good for old projects, all of them were building with the rtd theme, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like to keep the same behavior outside than inside RTD. I want to echo Santos' question: what would happen with old projects that weren't specifying the them? Will they start building with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming they target Frankly, I think switching them to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am -1 on this particular change, I think projects should keep the readthedocs theme if that is what they have been building their projects with. We can use a date-based feature flag if necessary, to ensure that projects before the feature flag get the If the user hasn't changed to a custom theme, I don't think we can accurately determine whether they want the default mkdocs theme or our theme, so i'm more inclined to just keep our theme for these users. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put some thoughts here about this. I moved the discussion a bit since it references multiple comments. |
||
|
||
def __init__(self, *args, **kwargs): | ||
super(BaseMkdocs, self).__init__(*args, **kwargs) | ||
|
@@ -133,11 +124,6 @@ def append_conf(self, **__): | |
# This supports using RTD's privacy improvements around analytics | ||
user_config['google_analytics'] = None | ||
|
||
# If using the readthedocs theme, apply the readthedocs.org overrides | ||
# These use a global readthedocs search | ||
# and customize the version selector. | ||
self.apply_theme_override(user_config) | ||
|
||
# Write the modified mkdocs configuration | ||
yaml.safe_dump( | ||
user_config, | ||
|
@@ -198,8 +184,6 @@ def build(self): | |
'--site-dir', self.build_dir, | ||
'--config-file', self.yaml_file, | ||
] | ||
if self.use_theme: | ||
build_command.extend(['--theme', 'readthedocs']) | ||
cmd_ret = self.run( | ||
*build_command, | ||
cwd=checkout_path, | ||
|
@@ -220,7 +204,7 @@ def get_theme_name(self, mkdocs_config): | |
theme_setting = mkdocs_config.get('theme') | ||
if isinstance(theme_setting, dict): | ||
# Full nested theme config (the new configuration) | ||
return theme_setting.get('name') or self.READTHEDOCS_THEME_NAME | ||
return theme_setting.get('name') or self.DEFAULT_THEME_NAME | ||
|
||
if theme_setting: | ||
# A string which is the name of the theme | ||
|
@@ -231,27 +215,7 @@ def get_theme_name(self, mkdocs_config): | |
# Use the name of the directory in this project's custom theme directory | ||
return theme_dir.rstrip('/').split('/')[-1] | ||
|
||
return self.READTHEDOCS_THEME_NAME | ||
|
||
def apply_theme_override(self, mkdocs_config): | ||
""" | ||
Apply theme overrides for the RTD theme (modifies the ``mkdocs_config`` parameter) | ||
In v0.17.0, the theme configuration switched | ||
from two separate configs (both optional) to a nested directive. | ||
How to override the theme depends on whether the new or old configuration | ||
is used. | ||
:see: http://www.mkdocs.org/about/release-notes/#theme-customization-1164 | ||
""" | ||
if self.get_theme_name(mkdocs_config) == self.READTHEDOCS_THEME_NAME: | ||
# Overriding the theme is only necessary | ||
# if the 'readthedocs' theme is used. | ||
theme_setting = mkdocs_config.get('theme') | ||
if isinstance(theme_setting, dict): | ||
theme_setting['custom_dir'] = self.READTHEDOCS_TEMPLATE_OVERRIDE_DIR | ||
else: | ||
mkdocs_config['theme_dir'] = self.READTHEDOCS_TEMPLATE_OVERRIDE_DIR | ||
return self.DEFAULT_THEME_NAME | ||
|
||
|
||
class MkdocsHTML(BaseMkdocs): | ||
|
@@ -264,4 +228,3 @@ class MkdocsJSON(BaseMkdocs): | |
type = 'mkdocs_json' | ||
builder = 'json' | ||
build_dir = '_build/json' | ||
use_theme = False |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the bug seen here which is currently visible on https://mkdocs.readthedocs.io/en/stable/