Skip to content

Commit eeb29ee

Browse files
louis-preclaude
andcommitted
Centralize site section config for both validators
Move site section definitions (name, root, urlPrefix) into config.ts as the single source of truth. Both validate-paths and validate-links now read from the shared config instead of defining their own lists. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 517876d commit eeb29ee

3 files changed

Lines changed: 30 additions & 52 deletions

File tree

codegen/lib/config.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
import { join } from 'node:path'
22

3-
// Site section roots (paths from repo root)
4-
export const apiReferenceRoot = join('docs', 'api-reference')
5-
export const guidesRoot = join('docs', 'guides')
6-
7-
// The published URL prefix for the API Reference site section on docs.seam.co.
8-
export const apiReferenceUrlPrefix = '/api'
9-
103
// The base URL for the published documentation site.
114
export const baseUrl = 'https://docs.seam.co/latest/'
125

136
// The URL prefix to strip when resolving absolute URLs to file paths.
147
export const siteUrlPrefix = '/latest'
158

9+
// Each site section is a GitBook site section with its own SUMMARY.md.
10+
export interface SiteSection {
11+
// Display name for logging/errors.
12+
name: string
13+
// Path from repo root to the section's content directory.
14+
root: string
15+
// Published URL prefix (e.g., '/api'). Empty string for the default section.
16+
urlPrefix: string
17+
}
18+
19+
export const siteSections: SiteSection[] = [
20+
{ name: 'Guides', root: join('docs', 'guides'), urlPrefix: '' },
21+
{
22+
name: 'API Reference',
23+
root: join('docs', 'api-reference'),
24+
urlPrefix: '/api',
25+
},
26+
]
27+
28+
// Convenience accessors (used by codegen)
29+
export const guidesRoot = siteSections[0]!.root
30+
export const apiReferenceRoot = siteSections[1]!.root
31+
export const apiReferenceUrlPrefix = siteSections[1]!.urlPrefix
32+
1633
// Derived paths
1734
export const apiReferenceSummaryPath = join(apiReferenceRoot, 'SUMMARY.md')

codegen/validate-links.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
import { existsSync, readdirSync, readFileSync } from 'node:fs'
22
import { dirname, join, resolve } from 'node:path'
33

4-
import {
5-
apiReferenceRoot,
6-
apiReferenceUrlPrefix,
7-
baseUrl,
8-
guidesRoot,
9-
siteUrlPrefix,
10-
} from './lib/config.js'
11-
12-
// Maps published URL prefixes to their site section root on disk.
13-
const siteSections: Array<{ urlPrefix: string; root: string }> = [
14-
{ urlPrefix: apiReferenceUrlPrefix, root: apiReferenceRoot },
15-
{ urlPrefix: '', root: guidesRoot },
16-
]
4+
import { baseUrl, siteSections, siteUrlPrefix } from './lib/config.js'
175

186
const absoluteUrlPattern = new RegExp(
197
`${baseUrl.replaceAll('.', '\\.')}[^)\\s]+`,

codegen/validate-paths.ts

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
import { existsSync, readFileSync } from 'node:fs'
22
import { join } from 'node:path'
33

4-
import { apiReferenceRoot, guidesRoot } from './lib/config.js'
5-
6-
interface SiteSection {
7-
name: string
8-
root: string
9-
summaryPath: string
10-
}
11-
12-
const siteSections: SiteSection[] = [
13-
{
14-
name: 'Guides',
15-
root: guidesRoot,
16-
summaryPath: join(guidesRoot, 'SUMMARY.md'),
17-
},
18-
{
19-
name: 'API Reference',
20-
root: apiReferenceRoot,
21-
summaryPath: join(apiReferenceRoot, 'SUMMARY.md'),
22-
},
23-
]
4+
import { siteSections } from './lib/config.js'
245

256
// Matches markdown links in SUMMARY.md: * [Title](path/to/file.md)
267
const summaryLinkPattern = /\[([^\]]*)\]\(([^)]+)\)/g
@@ -37,11 +18,6 @@ function slugify(heading: string): string {
3718
.trim()
3819
}
3920

40-
// Groups listed here contain files from multiple subdirectories by design,
41-
// so we only check that referenced files exist (not that their path prefix
42-
// matches the group slug).
43-
const exemptGroups = new Set<string>([])
44-
4521
interface PathMismatch {
4622
section: string
4723
line: number
@@ -53,9 +29,10 @@ interface PathMismatch {
5329
const mismatches: PathMismatch[] = []
5430

5531
for (const section of siteSections) {
56-
if (!existsSync(section.summaryPath)) continue
32+
const summaryPath = join(section.root, 'SUMMARY.md')
33+
if (!existsSync(summaryPath)) continue
5734

58-
const contents = readFileSync(section.summaryPath, 'utf-8')
35+
const contents = readFileSync(summaryPath, 'utf-8')
5936
const lines = contents.split('\n')
6037

6138
let currentGroup: string | null = null
@@ -93,11 +70,7 @@ for (const section of siteSections) {
9370
}
9471

9572
// Check 2: file path starts with the group slug
96-
if (
97-
currentGroup != null &&
98-
!exemptGroups.has(currentGroup) &&
99-
!linkPath.startsWith(currentGroup + '/')
100-
) {
73+
if (currentGroup != null && !linkPath.startsWith(currentGroup + '/')) {
10174
mismatches.push({
10275
section: section.name,
10376
line: i + 1,

0 commit comments

Comments
 (0)