File tree 2 files changed +40
-1
lines changed
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import re
3
+ import sys
4
+
5
+ CARDS_DIR = 'cards'
6
+
7
+ # Build a set of all valid card names (without .md extension)
8
+ valid_cards = set ()
9
+ for file in os .listdir (CARDS_DIR ):
10
+ if file .endswith ('.md' ):
11
+ valid_cards .add (file [:- 3 ]) # Remove .md
12
+
13
+ # Regex to match Obsidian-style internal links: [[Link Name]] or [[Link Name|Alias]]
14
+ link_pattern = re .compile (r'\[\[([^\]|\n\]]+)(?:\|[^\]]*)?\]\]' )
15
+
16
+ broken_links = []
17
+
18
+ for filename in os .listdir (CARDS_DIR ):
19
+ if not filename .endswith ('.md' ):
20
+ continue
21
+ path = os .path .join (CARDS_DIR , filename )
22
+ with open (path , 'r' , encoding = 'utf-8' ) as f :
23
+ for i , line in enumerate (f , 1 ):
24
+ for match in link_pattern .finditer (line ):
25
+ link_target = match .group (1 ).strip ()
26
+ # Obsidian links are case-sensitive and must match the filename (without .md)
27
+ if link_target not in valid_cards :
28
+ broken_links .append ((filename , i , link_target ))
29
+
30
+ if broken_links :
31
+ for card , line_num , link in broken_links :
32
+ print (f"Broken link in { card } (line { line_num } ): [[{ link } ]]" )
33
+ print (f"\n ERROR: { len (broken_links )} broken internal link(s) found." )
34
+ sys .exit (1 )
35
+ else :
36
+ print ("All internal links are valid." )
Original file line number Diff line number Diff line change 20
20
python -m pip install --upgrade pip
21
21
22
22
- name : Run card check script
23
- run : python .github/scripts/check-cards.py
23
+ run : python .github/scripts/check-cards.py
24
+
25
+ - name : Run internal link check script
26
+ run : python .github/scripts/check-internal-links.py
You can’t perform that action at this time.
0 commit comments