Skip to content

Commit

Permalink
Report already checked but broken remote links on all pages
Browse files Browse the repository at this point in the history
  • Loading branch information
da2x committed May 19, 2015
1 parent cb316c3 commit 34f02ad
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nikola/plugins/command/check.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 34f02ad

Please sign in to comment.