Skip to content
Permalink
Browse files

Report already checked but broken remote links on all pages

  • Loading branch information
da2x committed May 19, 2015
1 parent cb316c3 commit 34f02adbd89e279d43f8ef7f1819350e11407762
Showing with 4 additions and 4 deletions.
  1. +4 −4 nikola/plugins/command/check.py
@@ -173,7 +173,7 @@ def _execute(self, options, args):
sys.exit(1)

existing_targets = set([])
checked_remote_targets = []
checked_remote_targets = {}

def analyze(self, task, find_sources=False, check_remote=False):
rv = False
@@ -219,13 +219,13 @@ def analyze(self, task, find_sources=False, check_remote=False):
if parsed.netloc == base_url.netloc: # absolute URL to self.site
continue
if target in self.checked_remote_targets: # already checked this exact target
if self.checked_remote_targets[target] > 399:
self.logger.warn("Broken link in {0}: {1} [Error {2}]".format(filename, target, self.checked_remote_targets[target]))
continue
self.checked_remote_targets.append(target)

# Check the remote link works
req_headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 (Nikola)'} # I’m a real boy!
resp = requests.head(target, headers=req_headers)

self.checked_remote_targets[target] = resp.status_code
if resp.status_code > 399: # Error
self.logger.warn("Broken link in {0}: {1} [Error {2}]".format(filename, target, resp.status_code))
continue

0 comments on commit 34f02ad

Please sign in to comment.
You can’t perform that action at this time.