import type { Check, CheckIssue, PageCheckContext } from '../../types.ts' export function createMultipleH1Check(): Check { return { kind: 'page', id: 'seo/multiple-h1', name: 'Single H1', domain: 'seo', defaultSeverity: 'warning', description: 'Each page should have only one

element', essential: true, run(ctx: PageCheckContext): CheckIssue[] { const h1s = ctx.pageData.headings.filter(h => h.level === 1) if (h1s.length > 1) { const second = h1s[1]! return [{ message: `Page has ${h1s.length}

elements (expected 1)`, suggestion: 'Use only one

per page; use

-

for sub-headings', line: second.line, actual: `${h1s.length} h1 elements`, expected: '1 h1 element', }] } return [] }, } } export function createNoH1Check(): Check { return { kind: 'page', id: 'seo/no-h1', name: 'H1 Present', domain: 'seo', defaultSeverity: 'warning', description: 'Each page should have an

element', essential: true, run(ctx: PageCheckContext): CheckIssue[] { const h1s = ctx.pageData.headings.filter(h => h.level === 1) if (h1s.length === 0) { return [{ message: 'Page is missing an

element', suggestion: 'Add an

heading to identify the main topic of the page' }] } return [] }, } } export function createHeadingSkipCheck(): Check { return { kind: 'page', id: 'seo/heading-skip', name: 'Heading Hierarchy', domain: 'seo', defaultSeverity: 'info', description: 'Heading levels should not be skipped (e.g. h1 followed by h3)', essential: false, run(ctx: PageCheckContext): CheckIssue[] { const results: CheckIssue[] = [] const { headings } = ctx.pageData for (let i = 1; i < headings.length; i++) { const prev = headings[i - 1]! const curr = headings[i]! if (curr.level > prev.level + 1) { results.push({ message: `Heading level skipped from to `, suggestion: `Use instead of , or add the missing intermediate heading`, line: curr.line, actual: `h${prev.level} → h${curr.level}`, expected: `h${prev.level} → h${prev.level + 1}`, }) } } return results }, } }