Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print file names with external links #44

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions link-verifier/verify-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from termcolor import cprint
from multiprocessing import Pool
import traceback
from collections import defaultdict

MARKDOWN_SEARCH_TERM = r'\.md$'
# Regex to find a URL
Expand Down Expand Up @@ -314,6 +315,7 @@ def main():
broken_links = []
md_file_list = []
link_set = set()
link_to_files = defaultdict(set)
exclude_dirs = [dir.lower() for dir in args.exclude_dirs] if args.exclude_dirs else []

if args.user_agent != None:
Expand Down Expand Up @@ -353,6 +355,7 @@ def main():
urls = re.findall(URL_SEARCH_TERM, text)
for url in urls:
link_set.add(url[0])
link_to_files[url[0]].add(f_path)

# If allowlist file is passed, add those links to link_cache so that link check on those URLs can be bypassed.
if args.allowlist is not None:
Expand Down Expand Up @@ -393,10 +396,12 @@ def main():
is_broken, status_code = test_url(link)
if is_broken:
broken_links.append(link)
cprint(f'{status_code}\t{link}', 'red')
print("FILES:", link_to_files[link])
cprint(f'\t{status_code}\t{link}', 'red')
else:
if args.verbose:
cprint(f'{status_code}\t{link}', 'green')
print("FILES:", link_to_files[link])
cprint(f'\t{status_code}\t{link}', 'green')

# Return code > 0 to return error.
num_broken = len(broken_links)
Expand Down