Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Check REDIRECTIONS. Fixes #2026.
  • Loading branch information
da2x committed Sep 5, 2015
1 parent d2f5590 commit 41a9a82
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nikola/plugins/command/check.py
Expand Up @@ -45,7 +45,6 @@
from nikola.plugin_categories import Command
from nikola.utils import get_logger, STDERR_HANDLER


def _call_nikola_list(site):
files = []
deps = defaultdict(list)
Expand Down Expand Up @@ -178,6 +177,7 @@ def analyze(self, fname, find_sources=False, check_remote=False):
"""Analyze links on a page."""
rv = False
self.whitelist = [re.compile(x) for x in self.site.config['LINK_CHECK_WHITELIST']]
self.internal_redirects = [urljoin('/', _[0]) for _ in self.site.config['REDIRECTIONS']]
base_url = urlparse(self.site.config['BASE_URL'])
self.existing_targets.add(self.site.config['SITE_URL'])
self.existing_targets.add(self.site.config['BASE_URL'])
Expand Down Expand Up @@ -250,6 +250,12 @@ def analyze(self, fname, find_sources=False, check_remote=False):
if base_url.netloc == parsed.netloc and base_url.scheme == "https" and parsed.scheme == "http":
self.logger.warn("Mixed-content security for link in {0}: {1}".format(filename, target))

# Link to an internal REDIRECTIONS page
if target in self.internal_redirects:
redir_status_code = 301
redir_target = [_dest for _target, _dest in self.site.config['REDIRECTIONS'] if urljoin('/', _target) == target][0]
self.logger.warn("Remote link moved PERMANENTLY to \"{0}\" and should be updated in {1}: {2} [HTTP: 301]".format(redir_target, filename, target))

# Absolute links to other domains, skip
# Absolute links when using only paths, skip.
if ((parsed.scheme or target.startswith('//')) and parsed.netloc != base_url.netloc) or \
Expand Down

0 comments on commit 41a9a82

Please sign in to comment.