feat(exporter): SEO/Perf small improvements (canonical, lazy/async hero, dark token) + tests

This commit is contained in:
2025-11-14 20:49:47 +09:00
parent f6c54d1074
commit 0e3f569398
3 changed files with 38 additions and 2 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ describe('Exporter a11y/responsive enhancements', () => {
test('hero image alt derives from heading', () => {
const out = exportPage(makePage())
expect(out.html).toContain('<h1 id="hero-heading">Welcome</h1>')
expect(out.html).toContain('<img src="https://example.com/img.png" alt="Welcome" />')
expect(out.html).toMatch(/<img[^>]*src="https:\/\/example\.com\/img\.png"[^>]*alt="Welcome"[^>]*\/>/)
})
test('responsive and a11y CSS tokens exist', () => {
+3 -1
View File
@@ -108,7 +108,7 @@ function renderHero(section: { props: { heading: string; subheading?: string; im
${subheading ? `<p>${escapeHtml(subheading)}</p>` : ''}
</div>
<div class="media">
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" />
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" loading="lazy" decoding="async" />
</div>
</div>
</section>
@@ -237,6 +237,7 @@ function buildHead(page: Page) {
return `
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="canonical" href="/" />
<title>${escapeHtml(page.seo.title)}</title>
<meta name="description" content="${escapeHtml(page.seo.description)}" />
<meta property="og:title" content="${escapeHtml(page.seo.title)}" />
@@ -272,6 +273,7 @@ function buildCss(page: Page) {
.testimonial blockquote{ margin:0; font-style:italic; color:#1f2937 }
.testimonial figcaption{ color:#475569; margin-top:.25rem }
@media (max-width: 640px){ .container{ padding: 1rem } h1{ font-size: 1.5rem } }
@media (prefers-color-scheme: dark){ body{ color:#e5e7eb; background:#0b1020 } .feature-item{ background:#0f172a; border-color:#1f2937 } }
@media (prefers-reduced-motion: reduce){ *{ transition: none !important; animation: none !important } }
`
}
+34
View File
@@ -0,0 +1,34 @@
import { describe, it, expect } from 'vitest'
import { exportPage } from '@/lib/exporter/html'
import { pageSchema, type Page } from '@/lib/schema/page'
function makePage(): Page {
return pageSchema.parse({
title: 'SEO/Perf',
locale: 'en',
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
sections: [
{ type: 'hero', props: { heading: 'Welcome', subheading: 'Sub', imageUrl: 'https://img.example/hero.png' } },
],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 'SEO', description: 'Desc' },
})
}
describe('Exporter - small SEO/Perf improvements', () => {
it('includes canonical link and dark mode tokens; hero image lazy/async', () => {
const out = exportPage(makePage())
const html = out.html
const css = out.css
// canonical link present in head
expect(html).toMatch(/<link[^>]+rel="canonical"/)
// hero image has loading/decoding attributes
expect(html).toMatch(/<img[^>]*loading="lazy"/)
expect(html).toMatch(/<img[^>]*decoding="async"/)
// dark mode media query token exists
expect(css).toMatch(/@media \(prefers-color-scheme: dark\)/)
})
})