Skip to content

Commit

Permalink
Remote links all returned warnings when checked
Browse files Browse the repository at this point in the history
Successes should return here too, would otherwise proceed down to
line 256 and produce a warnig.
  • Loading branch information
da2x committed May 19, 2015
1 parent 7550c74 commit c09c93c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -10,6 +10,7 @@ Features
Bugfixes
--------

* All remotely checked links resulted in incorrect warnings (`nikola check -lr`)
* Exclude `<meta content="noindex" name="robots">` from sitemaps
* new_post paths are now relative to CWD (Issue #1325)

Expand Down
8 changes: 7 additions & 1 deletion nikola/plugins/command/check.py
Expand Up @@ -218,10 +218,16 @@ def analyze(self, task, find_sources=False, check_remote=False):
if parsed.netloc == base_url.netloc:
continue
# Check the remote link works
resp = requests.head(target)
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)
if resp.status_code > 399: # Error
self.logger.warn("Broken link in {0}: {1} [Error {2}]".format(filename, target, resp.status_code))
continue
elif resp.status_code <= 399: # The address leads *somewhere* that is not an error
self.logger.debug("Successfully checked remote link in {0}: {1} [HTTP: {2}]".format(filename, target, resp.status_code))
continue
self.logger.warn("Could not check remote link in {0}: {1} [Unknown problem]".format(filename, target))
continue

if url_type == 'rel_path':
target_filename = os.path.abspath(
Expand Down

0 comments on commit c09c93c

Please sign in to comment.