From f1d9bfb8913abd89e996f0ad483443921b8aea83 Mon Sep 17 00:00:00 2001 From: Akira Takahashi Date: Wed, 16 Oct 2024 14:20:19 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=AF=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AFCI=20:=20URL=E3=82=92=E3=82=B3=E3=83=9E?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=83=A9=E3=82=A4=E3=83=B3=E5=BC=95=E6=95=B0?= =?UTF-8?q?=E3=81=A7=E6=8C=87=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/script/link_check.py | 62 +++++++++++++++----------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/.github/workflows/script/link_check.py b/.github/workflows/script/link_check.py index 7cf0115ac4..fcb0c078f8 100644 --- a/.github/workflows/script/link_check.py +++ b/.github/workflows/script/link_check.py @@ -122,6 +122,10 @@ def add_link(origin_link: str): dest='check_outer_link', action='store_true', default=False) + argparser.add_argument("--url", + dest='url', + type=str, + default='') args = argparser.parse_args() if not args.check_inner_link and not args.check_outer_link: @@ -131,36 +135,40 @@ def add_link(origin_link: str): found_error = False current_dir = os.getcwd() outer_link_dict = dict() - for p in glob.glob("**/*.md", recursive=True): - dirname = os.path.dirname(p) - with open(p) as f: - text = f.read() - - inner_links, outer_links = find_all_links(text) - for link in outer_links: - if link in outer_link_dict: - outer_link_dict[link].append(p) - else: - outer_link_dict[link] = [p] - - if args.check_inner_link: - for link in inner_links: - rel_link = "" - if link.startswith("/"): - rel_link = os.path.join(current_dir, link.lstrip("/")) + if len(args.url) <= 0: + for p in glob.glob("**/*.md", recursive=True): + dirname = os.path.dirname(p) + with open(p) as f: + text = f.read() + + inner_links, outer_links = find_all_links(text) + for link in outer_links: + if link in outer_link_dict: + outer_link_dict[link].append(p) else: - rel_link = os.path.join(dirname, link) - - if link.endswith(".nolink"): - if os.path.exists(rel_link.rstrip(".nolink")): - print("nolinked {} href {} found.".format(p, link.rstrip(".nolink")), file=sys.stderr) - found_error = True - else: - if not os.path.exists(rel_link): - print("{} href {} not found.".format(p, link), file=sys.stderr) - found_error = True + outer_link_dict[link] = [p] + + if args.check_inner_link: + for link in inner_links: + rel_link = "" + if link.startswith("/"): + rel_link = os.path.join(current_dir, link.lstrip("/")) + else: + rel_link = os.path.join(dirname, link) + + if link.endswith(".nolink"): + if os.path.exists(rel_link.rstrip(".nolink")): + print("nolinked {} href {} found.".format(p, link.rstrip(".nolink")), file=sys.stderr) + found_error = True + else: + if not os.path.exists(rel_link): + print("{} href {} not found.".format(p, link), file=sys.stderr) + found_error = True if args.check_outer_link: + if len(args.url) > 0: + outer_link_dict[args.url] = "" + for link, from_list in outer_link_dict.items(): exists, reason = check_url(link) if not exists: