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

Remove all suffixes from filename and make it compatible with i18n plugins. #44

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions mkdocs_redirects/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import logging
import os
import pathlib
import posixpath
import textwrap

Expand Down Expand Up @@ -72,7 +73,9 @@ def get_relative_html_path(old_page, new_page, use_directory_urls):
def get_html_path(path, use_directory_urls):
"""Return the HTML file path for a given markdown file"""
parent, filename = posixpath.split(path)
name_orig = posixpath.splitext(filename)[0]

suffix = ''.join(pathlib.Path(filename).suffixes)
name_orig = filename.replace(suffix, '')

# Both `index.md` and `README.md` files are normalized to `index.html` during build
name = 'index' if name_orig in ('index', 'README') else name_orig
Expand Down Expand Up @@ -134,10 +137,8 @@ def on_post_build(self, config, **kwargs):
# External redirect targets are easy, just use it as the target path
if page_new.lower().startswith(('http://', 'https://')):
dest_path = page_new

elif page_new_without_hash in self.doc_pages:
dest_path = get_relative_html_path(page_old, page_new, use_directory_urls)

# If the redirect target isn't external or a valid internal page, throw an error
# Note: we use 'warn' here specifically; mkdocs treats warnings specially when in strict mode
else:
Expand Down