Compare commits

...

2 Commits

Author SHA1 Message Date
jaybe 1a405a54fa feat(export): extras 오버라이드 지원(robots/manifest) TDD 및 구현
Auto PR / open-pr (push) Successful in 22s
Auto Label PR / add-automerge-label (pull_request) Successful in 7s
CI / test (pull_request) Successful in 1m27s
2025-11-15 02:26:54 +09:00
jaybe 5c23cf3873 feat(seo): theme-color 메타 추가 및 hero 이미지 width/height로 CLS 개선(TDD)
Auto PR / open-pr (push) Successful in 19s
Auto Label PR / add-automerge-label (pull_request) Successful in 7s
CI / test (pull_request) Successful in 55s
2025-11-15 02:20:47 +09:00
4 changed files with 101 additions and 3 deletions
+47
View File
@@ -0,0 +1,47 @@
import { describe, it, expect } from 'vitest'
import { pageSchema, type Page } from '@/lib/schema/page'
import { buildExtrasForPage } from '@/lib/exporter/extras'
function makePage(): Page {
return pageSchema.parse({
title: 'Overrides Demo',
locale: 'en',
theme: { primaryColor: '#123456', fontFamily: 'Inter' },
sections: [
{ type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img.example/hero.png' } },
],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 'Overrides', description: 'Desc' },
})
}
describe('extras overrides', () => {
it('allows overriding robots.txt content', () => {
const page = makePage()
const extras = buildExtrasForPage(page, {
robotsText: 'User-agent: *\nDisallow: /private',
})
const robots = new TextDecoder().decode(extras['robots.txt'])
expect(robots).toContain('Disallow: /private')
})
it('allows overriding manifest fields (name, short_name, start_url, display, theme_color)', () => {
const page = makePage()
const extras = buildExtrasForPage(page, {
manifest: {
name: 'Custom Name',
short_name: 'Custom',
start_url: '/home',
display: 'minimal-ui',
theme_color: '#abcdef',
},
})
const manifestRaw = new TextDecoder().decode(extras['site.webmanifest'])
const manifest = JSON.parse(manifestRaw)
expect(manifest.name).toBe('Custom Name')
expect(manifest.short_name).toBe('Custom')
expect(manifest.start_url).toBe('/home')
expect(manifest.display).toBe('minimal-ui')
expect(manifest.theme_color).toBe('#abcdef')
})
})
+21 -2
View File
@@ -1,13 +1,25 @@
import type { Page } from '@/lib/schema/page'
type ExtrasOverrides = {
robotsText?: string
manifest?: Partial<{
name: string
short_name: string
start_url: string
display: string
theme_color: string
}>
}
// Sheets 템플릿 등 ZIP 루트/서브 경로에 포함할 추가 파일(extras)을 구성한다.
// - actionUrl이 비어있을 때만 Google Apps Script 템플릿을 포함한다.
export function buildExtrasForPage(page: Page): Record<string, Uint8Array> {
export function buildExtrasForPage(page: Page, overrides?: ExtrasOverrides): Record<string, Uint8Array> {
const extras: Record<string, Uint8Array> = {}
const te = new TextEncoder()
// Always provide a baseline robots.txt
const robots = `User-agent: *\nDisallow:`
const robotsDefault = `User-agent: *\nDisallow:`
const robots = overrides?.robotsText ?? robotsDefault
extras['robots.txt'] = te.encode(robots)
// Provide a minimal site.webmanifest derived from Page
@@ -20,6 +32,13 @@ export function buildExtrasForPage(page: Page): Record<string, Uint8Array> {
start_url: '/',
display: 'standalone',
theme_color: page.theme?.primaryColor ?? '#000000',
...((overrides?.manifest as object) || {}),
} as {
name: string
short_name: string
start_url: string
display: string
theme_color: string
}
extras['site.webmanifest'] = te.encode(JSON.stringify(manifest))
} catch {}
+2 -1
View File
@@ -124,7 +124,7 @@ function renderHero(section: { props: { heading: string; subheading?: string; im
${subheading.length > 0 ? `<p>${escapeHtml(subheading)}</p>` : ''}
</div>
<div class="media">
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" loading="lazy" decoding="async" />
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" loading="lazy" decoding="async" width="1200" height="675" />
</div>
</div>
</section>
@@ -256,6 +256,7 @@ function buildHead(page: Page) {
<link rel="canonical" href="/" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="icon" href="/favicon.ico" />
<meta name="theme-color" content="${page.theme.primaryColor}" />
<title>${escapeHtml(page.seo.title)}</title>
<meta name="description" content="${escapeHtml(page.seo.description)}" />
<meta property="og:title" content="${escapeHtml(page.seo.title)}" />
@@ -0,0 +1,31 @@
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 2',
locale: 'en',
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
sections: [
{ type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img.example/hero.png' } },
],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 'SEO2', description: 'Desc2' },
})
}
describe('Exporter - theme-color meta and hero image intrinsic size', () => {
it('includes theme-color meta using page.theme.primaryColor', () => {
const out = exportPage(makePage())
const html = out.html
expect(html).toMatch(/<meta name="theme-color" content="#0ea5e9"\s*\/>/)
})
it('renders hero image with width/height attributes for CLS reduction', () => {
const out = exportPage(makePage())
const html = out.html
expect(html).toMatch(/<img[^>]*\swidth="[0-9]+"/)
expect(html).toMatch(/<img[^>]*\sheight="[0-9]+"/)
})
})