Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Report already checked but broken remote links on all pages
- Loading branch information
Showing
with
4 additions
and
4 deletions.
-
+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 |
|
|