diff --git a/scripts/audit-release.mjs b/scripts/audit-release.mjs index 266b8fad..7f65ae34 100644 --- a/scripts/audit-release.mjs +++ b/scripts/audit-release.mjs @@ -61,6 +61,9 @@ if (existsSync(dist)) walk(dist) const textExtensions = new Set(['.html', '.xml', '.txt', '.webmanifest', '.css', '.js']) const assetPattern = /(?:href|src|content)=["']([^"']+)["']/g +const htmlTagText = (value = '') => value.replace(/<[^>]*>/g, '').trim() +const attributeValue = (tag, name) => + tag.match(new RegExp(`\\b${name}\\s*=\\s*["']([^"']*)["']`, 'i'))?.[1]?.trim() ?? '' for (const file of files.filter((path) => textExtensions.has(extname(path)))) { const source = readFileSync(file, 'utf8') @@ -74,6 +77,19 @@ for (const file of files.filter((path) => textExtensions.has(extname(path)))) { if (extname(file) !== '.html') continue + const title = source.match(/]*)?>([\s\S]*?)<\/title>/i)?.[1] + if (!htmlTagText(title)) failures.push(`${label}: missing document title`) + + const descriptionTag = [...source.matchAll(/]*>/gi)] + .map(([tag]) => tag) + .find((tag) => attributeValue(tag, 'name').toLowerCase() === 'description') + if (!descriptionTag || !attributeValue(descriptionTag, 'content')) { + failures.push(`${label}: missing meta description`) + } + + const h1Count = [...source.matchAll(/ ({ params: { id: post.id }, - props: { title: post.data.title } + props: { title: post.data.title, description: post.data.description } })) } -interface Props { title: string } -const { title } = Astro.props +interface Props { title: string; description: string } +const { title, description } = Astro.props const base = import.meta.env.BASE_URL.replace(/\/$/, '') const destination = `${base}/blog/${Astro.params.id}` const canonical = new URL(destination, Astro.site) --- - + {title} +