Skip to content

Commit e9465dc

Browse files
louis-preclaude
andcommitted
Improve link validator: check asset links and merge validation jobs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 666660c commit e9465dc

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

.github/workflows/generate.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ jobs:
6666
commit_user_name: ${{ secrets.GIT_USER_NAME }}
6767
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
6868
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>
69-
validate-paths:
70-
name: Validate paths
69+
validate:
70+
name: Validate paths and links
7171
needs: commit
7272
runs-on: ubuntu-latest
7373
timeout-minutes: 30
@@ -80,17 +80,5 @@ jobs:
8080
uses: ./.github/actions/setup
8181
- name: Validate SUMMARY.md paths
8282
run: npm run validate-paths
83-
validate-links:
84-
name: Validate links
85-
needs: commit
86-
runs-on: ubuntu-latest
87-
timeout-minutes: 30
88-
steps:
89-
- name: Checkout
90-
uses: actions/checkout@v4
91-
with:
92-
ref: ${{ github.head_ref }}
93-
- name: Setup
94-
uses: ./.github/actions/setup
9583
- name: Validate cross-site links
9684
run: npm run validate-links

codegen/validate-links.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ function checkRelativeLink(file: string, line: number, rawLink: string): void {
8888
const linkPath = rawLink.replace(/ "mention"$/, '').split('#')[0]
8989
if (linkPath == null || linkPath === '') return
9090

91-
// Skip asset references
92-
if (linkPath.includes('.gitbook/assets')) return
93-
9491
// Strip GitBook markdown escapes and decode URL encoding
9592
const cleanPath = decodeURIComponent(
9693
linkPath.replaceAll('\\(', '(').replaceAll('\\)', ')').replaceAll('\\', ''),
@@ -99,6 +96,19 @@ function checkRelativeLink(file: string, line: number, rawLink: string): void {
9996
const fileDir = dirname(file)
10097
const resolved = resolve(fileDir, cleanPath)
10198

99+
// Check asset references exist
100+
if (linkPath.includes('.gitbook/assets')) {
101+
if (!existsSync(resolved)) {
102+
brokenLinks.push({
103+
file,
104+
line,
105+
url: rawLink,
106+
reason: `Asset not found: ${resolved}`,
107+
})
108+
}
109+
return
110+
}
111+
102112
// Check if target exists as file, as README.md in directory, or as directory
103113
if (!existsSync(resolved) && !existsSync(join(resolved, 'README.md'))) {
104114
brokenLinks.push({

0 commit comments

Comments
 (0)