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

add 'allow_html_redirect' configuration option to avoid printing warning when redirecting .html URLs #50

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion mkdocs_redirects/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ def get_html_path(path, use_directory_urls):
class RedirectPlugin(BasePlugin):
# Any options that this plugin supplies should go here.
config_scheme = (
('allow_html_redirect', config_options.Type(bool, default=False)),
('redirect_maps', config_options.Type(dict, default={})), # note the trailing comma
)

# Build a list of redirects on file generation
def on_files(self, files, config, **kwargs):
self.redirects = self.config.get('redirect_maps', {})

allow_html = self.config.get('allow_html_redirect', False)

# Validate user-provided redirect "old files"
for page_old in self.redirects.keys():
if not utils.is_markdown_file(page_old):
log.warning("redirects plugin: '%s' is not a valid markdown file!", page_old)
if not (allow_html and page_old.lower().endswith(('html', 'htm'))):
log.warning("redirects plugin: '%s' is not a valid markdown file!", page_old)
Copy link

Choose a reason for hiding this comment

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

should be ... not a valid md or html ..., yes?


# Build a dict of known document pages to validate against later
self.doc_pages = {}
Expand Down