Skip to content
Merged
Show file tree
Hide file tree
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
56 changes: 55 additions & 1 deletion scripts/validate-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ function buildValidPaths(): Set<string> {
paths.add(p)
}

// App routes (behind auth / mobile-ui) — content may link to these
for (const p of [
'/profile',
'/profile/backup',
'/profile/edit',
'/profile/exchange-rate',
'/profile/identity-verification',
'/home',
'/send',
'/request',
'/settings',
'/history',
'/points',
'/recover-funds',
]) {
paths.add(p)
}

const countrySlugs = listDirs(path.join(CONTENT_DIR, 'countries'))
const competitorSlugs = listDirs(path.join(CONTENT_DIR, 'compare'))
const payWithSlugs = listDirs(path.join(CONTENT_DIR, 'pay-with'))
Expand Down Expand Up @@ -187,6 +205,30 @@ function isInternalLink(url: string): boolean {
return true
}

// --- Frontmatter parsing ---

function parseFrontmatter(content: string): Record<string, unknown> {
const match = content.match(/^---\n([\s\S]*?)\n---/)
if (!match) return {}
const frontmatter: Record<string, unknown> = {}
for (const line of match[1].split('\n')) {
const colonIdx = line.indexOf(':')
if (colonIdx === -1) continue
const key = line.slice(0, colonIdx).trim()
const value = line.slice(colonIdx + 1).trim()
if (value === 'true') frontmatter[key] = true
else if (value === 'false') frontmatter[key] = false
else frontmatter[key] = value
}
return frontmatter
}

function isPublished(content: string): boolean {
const fm = parseFrontmatter(content)
// If published is explicitly false, skip the file
return fm.published !== false
}

// --- Scan content files ---

function getAllMdFiles(dir: string): string[] {
Expand Down Expand Up @@ -225,8 +267,17 @@ function main() {
const broken: BrokenLink[] = []
let totalLinks = 0

let skippedUnpublished = 0

for (const file of files) {
const content = fs.readFileSync(file, 'utf-8')

// Skip unpublished/draft content — links to not-yet-built routes are expected
if (!isPublished(content)) {
skippedUnpublished++
continue
}

const links = extractLinks(content)
totalLinks += links.length

Expand All @@ -246,7 +297,10 @@ function main() {
}

// --- Report ---
console.log(`Checked ${totalLinks} internal links across ${files.length} files\n`)
if (skippedUnpublished > 0) {
console.log(` Skipped ${skippedUnpublished} unpublished files\n`)
}
console.log(`Checked ${totalLinks} internal links across ${files.length - skippedUnpublished} published files\n`)

if (broken.length === 0) {
console.log('✓ No broken internal links found!')
Expand Down
2 changes: 1 addition & 1 deletion src/content
Loading