Navigation Menu

Skip to content

Commit

Permalink
Fix #2224 -- don’t redirect WP ?p links in subdirs
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jan 22, 2016
1 parent 9b441bd commit 2abf9b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -14,6 +14,8 @@ Features
Bugfixes
--------

* Don’t attempt to create redirects for URLs with query strings in
WordPress imports if the site is in a subdirectory (Issue #2224)
* Honor ``MATHJAX_CONFIG``
* Display tags and archives in a unified format, with the date on the
left, instead of a misplaced dash in tags (Issue #2212)
Expand Down
8 changes: 5 additions & 3 deletions nikola/plugins/basic_import.py
Expand Up @@ -76,8 +76,11 @@ def get_channel_from_file(cls, filename):
return channel

@staticmethod
def configure_redirections(url_map):
def configure_redirections(url_map, base_dir=''):
"""Configure redirections from an url_map."""
index = base_dir + 'index.html'
if index.startswith('/'):
index = index[1:]
redirections = []
for k, v in url_map.items():
if not k[-1] == '/':
Expand All @@ -86,11 +89,10 @@ def configure_redirections(url_map):
# remove the initial "/" because src is a relative file path
src = (urlparse(k).path + 'index.html')[1:]
dst = (urlparse(v).path)
if src == 'index.html':
if src == index:
utils.LOGGER.warn("Can't do a redirect for: {0!r}".format(k))
else:
redirections.append((src, dst))

return redirections

def generate_base_site(self):
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/command/import_wordpress.py
Expand Up @@ -334,7 +334,7 @@ def show_info_about_mising_module(modulename):
self.context['TRANSLATIONS'] = format_default_translations_config(
self.extra_languages)
self.context['REDIRECTIONS'] = self.configure_redirections(
self.url_map)
self.url_map, self.base_dir)
if self.timezone:
self.context['TIMEZONE'] = self.timezone
if self.export_categories_as_categories:
Expand Down

0 comments on commit 2abf9b5

Please sign in to comment.