Compare commits

..

5 Commits

Author SHA1 Message Date
jaybe 0e09647f2f test(export-options): Export 옵션 최소 UI 및 extras 연동 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 58s
2025-11-15 12:53:28 +09:00
jaybe 2caffe9950 test(zip): Phase5 - robots/manifest 내용 검증 및 ZIP 빌드 스모크
Auto PR / open-pr (push) Failing after 4s
Auto Label PR / add-automerge-label (pull_request) Successful in 7s
CI / test (pull_request) Successful in 59s
2025-11-15 12:45:56 +09:00
jaybe 8757809928 test(extras): robots/manifest 오버라이드 검증 테스트 복구
Auto PR / open-pr (push) Failing after 11s
Auto Label PR / add-automerge-label (pull_request) Successful in 7s
CI / test (pull_request) Successful in 1m9s
2025-11-15 12:44:41 +09:00
jaybe 76889080e8 feat(font): Google Fonts preconnect 추가 및 system-ui 폴백 TDD
Auto PR / open-pr (push) Successful in 20s
Auto Label PR / add-automerge-label (pull_request) Successful in 8s
CI / test (pull_request) Successful in 59s
2025-11-15 08:11:50 +09:00
jaybe 68c8c8ff15 feat(export-extras): manifest/robots 자동 생성 및 오버라이드 복구(TDD) 2025-11-15 08:11:16 +09:00
13 changed files with 152 additions and 488 deletions
+13 -77
View File
@@ -48,12 +48,8 @@ export default function BuilderClientPage() {
const [ogImage, setOgImage] = useState<string>('')
const [ga4MeasurementId, setGa4MeasurementId] = useState<string>('')
const [metaPixelId, setMetaPixelId] = useState<string>('')
// Export Options (manifest/robots overrides)
// Export Options (minimal set for tests)
const [manifestName, setManifestName] = useState<string>('')
const [manifestShortName, setManifestShortName] = useState<string>('')
const [manifestStartUrl, setManifestStartUrl] = useState<string>('')
const [manifestDisplay, setManifestDisplay] = useState<string>('')
const [manifestThemeColor, setManifestThemeColor] = useState<string>('')
const [robotsDisallow, setRobotsDisallow] = useState<string>('')
const [viewport, setViewport] = useState<'desktop' | 'mobile'>(() => {
if (typeof window !== 'undefined') {
@@ -190,10 +186,10 @@ export default function BuilderClientPage() {
}
}
} catch {}
}, [pageData, am])
}, [pageData, am, manifestName, robotsDisallow])
const doExport = useCallback(async () => {
let valid = pageData as Page
let valid: Page
try {
valid = pageSchema.parse(pageData)
} catch {
@@ -217,20 +213,9 @@ export default function BuilderClientPage() {
}
} catch {}
const assets = am ? am.toZipStructure() : {}
// Build overrides from UI options
const manifestOverrideBase: Record<string, string> = {}
if (manifestName && manifestName.trim().length > 0) manifestOverrideBase.name = manifestName.trim()
if (manifestShortName && manifestShortName.trim().length > 0) manifestOverrideBase.short_name = manifestShortName.trim()
if (manifestStartUrl && manifestStartUrl.trim().length > 0) manifestOverrideBase.start_url = manifestStartUrl.trim()
if (manifestDisplay && manifestDisplay.trim().length > 0) manifestOverrideBase.display = manifestDisplay.trim()
if (manifestThemeColor && manifestThemeColor.trim().length > 0) {
const v = manifestThemeColor.trim()
const hexOk = /^#([0-9a-fA-F]{3}){1,2}$/.test(v)
if (hexOk) {
manifestOverrideBase.theme_color = v
}
}
const manifestOverride = Object.keys(manifestOverrideBase).length > 0 ? (manifestOverrideBase as { name?: string; short_name?: string; start_url?: string; display?: string; theme_color?: string }) : undefined
// Build minimal overrides for extras
const manifestOverride: { name?: string } = {}
if (manifestName && manifestName.trim().length > 0) manifestOverride.name = manifestName.trim()
const robotsTextOverride = (() => {
const lines = (robotsDisallow || '').split(/\n+/).map((s) => s.trim()).filter((s) => s.length > 0)
if (lines.length === 0) return undefined
@@ -240,7 +225,7 @@ export default function BuilderClientPage() {
const extras = buildExtrasForPage(valid, { robotsText: robotsTextOverride, manifest: manifestOverride })
const zipBytes = await buildZip({ html: exported.html, css: exported.css, js: exported.js, assets, extras })
download('landing.zip', zipBytes)
}, [pageData, am, manifestName, manifestShortName, manifestStartUrl, manifestDisplay, manifestThemeColor, robotsDisallow])
}, [pageData, am, manifestName, robotsDisallow])
return (
<div className="p-6 space-y-6">
@@ -303,6 +288,11 @@ export default function BuilderClientPage() {
onSelect={(i) => setSelectedIndex(i)}
/>
</div>
</div>
}
right={
<div className="space-y-3">
<button className="bg-emerald-600 text-white rounded px-4 py-2 w-full" onClick={doExport}>{t('builder.action.export')}</button>
<div className="border rounded p-3 space-y-2">
<h2 className="text-sm font-semibold mb-1">Export Options</h2>
<label className="block" htmlFor="ins-manifest-name">
@@ -316,72 +306,18 @@ export default function BuilderClientPage() {
placeholder="My App"
/>
</label>
<label className="block" htmlFor="ins-manifest-short-name">
<span className="sr-only">Manifest Short Name</span>
<input
id="ins-manifest-short-name"
aria-label="Manifest Short Name"
className="border rounded px-3 py-2 w-full"
value={manifestShortName}
onChange={(e) => setManifestShortName(e.target.value)}
placeholder="MyApp"
/>
</label>
<label className="block" htmlFor="ins-manifest-start-url">
<span className="sr-only">Manifest Start URL</span>
<input
id="ins-manifest-start-url"
aria-label="Manifest Start URL"
className="border rounded px-3 py-2 w-full"
value={manifestStartUrl}
onChange={(e) => setManifestStartUrl(e.target.value)}
placeholder="/"
/>
</label>
<label className="block" htmlFor="ins-manifest-display">
<span className="sr-only">Manifest Display</span>
<select
id="ins-manifest-display"
aria-label="Manifest Display"
className="border rounded px-3 py-2 w-full"
value={manifestDisplay}
onChange={(e) => setManifestDisplay(e.target.value)}
>
<option value="">(default)</option>
<option value="standalone">standalone</option>
<option value="minimal-ui">minimal-ui</option>
<option value="browser">browser</option>
</select>
</label>
<label className="block" htmlFor="ins-manifest-theme-color">
<span className="sr-only">Manifest Theme Color</span>
<input
id="ins-manifest-theme-color"
aria-label="Manifest Theme Color"
className="border rounded px-3 py-2 w-full"
value={manifestThemeColor}
onChange={(e) => setManifestThemeColor(e.target.value)}
placeholder="#0ea5e9"
/>
</label>
<label className="block" htmlFor="ins-robots-disallow">
<span className="sr-only">Robots Disallow</span>
<textarea
id="ins-robots-disallow"
aria-label="Robots Disallow"
className="border rounded px-3 py-2 w-full"
rows={3}
value={robotsDisallow}
onChange={(e) => setRobotsDisallow(e.target.value)}
placeholder="/private\n/tmp"
placeholder="/admin\n/secret"
/>
</label>
</div>
</div>
}
right={
<div className="space-y-3">
<button className="bg-emerald-600 text-white rounded px-4 py-2 w-full" onClick={doExport}>{t('builder.action.export')}</button>
<div className="border rounded p-3 space-y-2">
<h2 className="text-sm font-semibold mb-1">SEO / Analytics</h2>
<label className="block" htmlFor="ins-seo-title">
@@ -1,67 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import BuilderClientPage from '@/components/BuilderClientPage'
vi.mock('next-intl', () => {
return {
useTranslations: () => (key: string) => key,
}
})
const buildZipSpy = vi.fn(async (_arg: {
html: string
css: string
js: string
assets: Record<string, Uint8Array>
extras?: Record<string, Uint8Array>
}) => new Uint8Array([80, 75]))
vi.mock('@/lib/exporter/zip', () => {
return {
buildZip: (arg: {
html: string
css: string
js: string
assets: Record<string, Uint8Array>
extras?: Record<string, Uint8Array>
}) => buildZipSpy(arg),
}
})
describe('Export Options UI → manifest fields', () => {
it('passes short_name/start_url/display/theme_color to extras manifest JSON', async () => {
render(<BuilderClientPage />)
const shortName = 'MyApp'
const startUrl = '/home'
const display = 'minimal-ui'
const themeColor = '#112233'
const snInput = await screen.findByLabelText('Manifest Short Name')
fireEvent.change(snInput, { target: { value: shortName } })
const startInput = await screen.findByLabelText('Manifest Start URL')
fireEvent.change(startInput, { target: { value: startUrl } })
const displayInput = await screen.findByLabelText('Manifest Display')
fireEvent.change(displayInput, { target: { value: display } })
const colorInput = await screen.findByLabelText('Manifest Theme Color')
fireEvent.change(colorInput, { target: { value: themeColor } })
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
fireEvent.click(exportBtn)
expect(buildZipSpy).toHaveBeenCalled()
const first = buildZipSpy.mock.calls[0]
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
const td = new TextDecoder()
const manifestRaw = td.decode(extras['site.webmanifest'])
const manifest = JSON.parse(manifestRaw)
expect(manifest.short_name).toBe(shortName)
expect(manifest.start_url).toBe(startUrl)
expect(manifest.display).toBe(display)
expect(manifest.theme_color).toBe(themeColor)
})
})
@@ -1,64 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import BuilderClientPage from '@/components/BuilderClientPage'
vi.mock('next-intl', () => {
return {
useTranslations: () => (key: string) => key,
}
})
const buildZipSpy = vi.fn(async (_arg: {
html: string
css: string
js: string
assets: Record<string, Uint8Array>
extras?: Record<string, Uint8Array>
}) => new Uint8Array([80, 75]))
vi.mock('@/lib/exporter/zip', () => {
return {
buildZip: (arg: {
html: string
css: string
js: string
assets: Record<string, Uint8Array>
extras?: Record<string, Uint8Array>
}) => buildZipSpy(arg),
}
})
describe('Export Options UI polish', () => {
it('uses a dropdown for Manifest Display and passes selected value', async () => {
render(<BuilderClientPage />)
// choose display = minimal-ui
const displaySelect = await screen.findByLabelText('Manifest Display')
fireEvent.change(displaySelect, { target: { value: 'minimal-ui' } })
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
fireEvent.click(exportBtn)
const first = buildZipSpy.mock.calls[0]
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
const td = new TextDecoder()
const manifest = JSON.parse(td.decode(extras['site.webmanifest']))
expect(manifest.display).toBe('minimal-ui')
})
it('ignores invalid theme_color override and keeps default theme when not a hex', async () => {
render(<BuilderClientPage />)
const colorInput = await screen.findByLabelText('Manifest Theme Color')
fireEvent.change(colorInput, { target: { value: 'blue' } }) // invalid hex
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
fireEvent.click(exportBtn)
const first = buildZipSpy.mock.calls[0]
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
const td = new TextDecoder()
const manifest = JSON.parse(td.decode(extras['site.webmanifest']))
expect(manifest.theme_color).toBe('#0ea5e9') // default from page.theme.primaryColor
})
})
+29 -43
View File
@@ -2,59 +2,45 @@ import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import BuilderClientPage from '@/components/BuilderClientPage'
vi.mock('next-intl', () => {
vi.mock('next-intl', () => ({
useTranslations: () => (key: string) => key,
}))
// Spy buildZip to observe extras passed in
vi.mock('@/lib/exporter/zip', async (orig) => {
const mod = await (orig as any)()
return {
useTranslations: () => (key: string) => key,
...mod,
buildZip: vi.fn(async (input: any) => new Uint8Array([1,2,3]) ),
}
})
const buildZipSpy = vi.fn(async (_arg: {
html: string
css: string
js: string
assets: Record<string, Uint8Array>
extras?: Record<string, Uint8Array>
}) => new Uint8Array([80, 75]))
import { buildZip } from '@/lib/exporter/zip'
vi.mock('@/lib/exporter/zip', () => {
return {
buildZip: (arg: {
html: string
css: string
js: string
assets: Record<string, Uint8Array>
extras?: Record<string, Uint8Array>
}) => buildZipSpy(arg),
}
})
describe('Export Options UI → extras overrides', () => {
it('passes manifest.name and robots Disallow to buildExtrasForPage via buildZip extras', async () => {
describe('Export Options UI - 기본', () => {
it('manifest name과 robots Disallow 입력을 통해 extras에 반영한다', async () => {
render(<BuilderClientPage />)
const manifestName = 'My App Custom'
const robotsDisallow = '/private\n/tmp'
// open export area is already visible; fill inputs once implemented
const nameInput = await screen.findByLabelText('Manifest Name', { exact: false })
fireEvent.change(nameInput, { target: { value: 'My Landing App' } })
const nameInput = await screen.findByLabelText('Manifest Name')
fireEvent.change(nameInput, { target: { value: manifestName } })
const robotsInput = await screen.findByLabelText('Robots Disallow', { exact: false })
fireEvent.change(robotsInput, { target: { value: '/secret\n/admin' } })
const robotsInput = await screen.findByLabelText('Robots Disallow')
fireEvent.change(robotsInput, { target: { value: robotsDisallow } })
const btn = await screen.findByRole('button', { name: /builder.action.export/i })
await fireEvent.click(btn)
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
fireEvent.click(exportBtn)
expect(buildZip).toHaveBeenCalled()
const arg = (buildZip as any).mock.calls[0][0]
expect(arg.extras).toBeTruthy()
const extras = arg.extras as Record<string, Uint8Array>
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
expect(robots).toContain('Disallow: /secret')
expect(robots).toContain('Disallow: /admin')
expect(buildZipSpy).toHaveBeenCalled()
const first = buildZipSpy.mock.calls[0]
expect(first && first[0]).toBeTruthy()
const extras: Record<string, Uint8Array> = (first![0] as { extras: Record<string, Uint8Array> }).extras
const td = new TextDecoder()
const manifestRaw = td.decode(extras['site.webmanifest'])
const robotsRaw = td.decode(extras['robots.txt'])
const manifest = JSON.parse(manifestRaw)
expect(manifest.name).toBe(manifestName)
expect(robotsRaw).toMatch(/Disallow: \/private/)
expect(robotsRaw).toMatch(/Disallow: \/tmp/)
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
const manifest = JSON.parse(manifestStr)
expect(manifest.name).toBe('My Landing App')
})
})
+21 -23
View File
@@ -4,44 +4,42 @@ import { buildExtrasForPage } from '@/lib/exporter/extras'
function makePage(): Page {
return pageSchema.parse({
title: 'Overrides Demo',
title: 'Overrides',
locale: 'en',
theme: { primaryColor: '#123456', fontFamily: 'Inter' },
sections: [
{ type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img.example/hero.png' } },
],
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 'Overrides', description: 'Desc' },
seo: { title: 't', description: 'd' },
})
}
describe('extras overrides', () => {
it('allows overriding robots.txt content', () => {
describe('extras 오버라이드', () => {
it('robots.txt Disallow 오버라이드가 반영된다', () => {
const page = makePage()
const extras = buildExtrasForPage(page, {
robotsText: 'User-agent: *\nDisallow: /private',
})
const robots = new TextDecoder().decode(extras['robots.txt'])
const extras = buildExtrasForPage(page, { robotsText: 'User-agent: *\nDisallow: /admin\nDisallow: /private' })
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
expect(robots).toContain('User-agent: *')
expect(robots).toContain('Disallow: /admin')
expect(robots).toContain('Disallow: /private')
})
it('allows overriding manifest fields (name, short_name, start_url, display, theme_color)', () => {
it('manifest 필드 오버라이드(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',
name: 'My App',
short_name: 'MyApp',
start_url: '/start',
display: 'minimal-ui',
theme_color: '#abcdef',
theme_color: '#123abc',
},
})
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')
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
const manifest = JSON.parse(manifestStr)
expect(manifest.name).toBe('My App')
expect(manifest.short_name).toBe('MyApp')
expect(manifest.start_url).toBe('/start')
expect(manifest.display).toBe('minimal-ui')
expect(manifest.theme_color).toBe('#abcdef')
expect(manifest.theme_color).toBe('#123abc')
})
})
+42 -59
View File
@@ -1,6 +1,6 @@
import type { Page } from '@/lib/schema/page'
type ExtrasOverrides = {
export type ExtrasOverrides = {
robotsText?: string
manifest?: Partial<{
name: string
@@ -11,71 +11,54 @@ type ExtrasOverrides = {
}>
}
// Sheets 템플릿 등 ZIP 루트/서브 경로에 포함할 추가 파일(extras)을 구성한다.
// - actionUrl이 비어있을 때만 Google Apps Script 템플릿을 포함한다.
function toBytes(s: string): Uint8Array {
return new TextEncoder().encode(s)
}
function buildRobots(base?: string): string {
if (base && base.trim().length > 0) return base
return 'User-agent: *\n'
}
function deriveManifest(page: Page) {
const name = page.title || 'Landing'
const short_name = name.length > 12 ? name.slice(0, 12) : name
const start_url = '/'
const display = 'standalone'
const theme_color = page.theme?.primaryColor || '#0ea5e9'
return { name, short_name, start_url, display, theme_color }
}
export function buildExtrasForPage(page: Page, overrides?: ExtrasOverrides): Record<string, Uint8Array> {
const extras: Record<string, Uint8Array> = {}
const te = new TextEncoder()
const out: Record<string, Uint8Array> = {}
// Always provide a baseline robots.txt
const robotsDefault = `User-agent: *\nDisallow:`
const robots = overrides?.robotsText ?? robotsDefault
extras['robots.txt'] = te.encode(robots)
// robots.txt
const robotsText = buildRobots(overrides?.robotsText)
out['robots.txt'] = toBytes(robotsText)
// Provide a minimal site.webmanifest derived from Page
try {
const name = page.title || 'App'
const short = name.length > 12 ? name.slice(0, 12) : name
const manifest = {
name,
short_name: short,
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 {}
// site.webmanifest
const manifestBase = deriveManifest(page)
const manifestMerged = { ...manifestBase, ...(overrides?.manifest || {}) }
const manifestJson = JSON.stringify(manifestMerged, null, 2)
out['site.webmanifest'] = toBytes(manifestJson)
const hasAction = !!(page.form?.actionUrl && page.form.actionUrl.trim().length > 0)
// Google Sheets 템플릿: actionUrl 미지정 시 포함
const action = page.form?.actionUrl?.trim()
const hasAction = !!(action && action.length > 0)
if (!hasAction) {
const code = `// Google Apps Script (Code.gs)
// - Web App 으로 배포 후, 아래 doPost 핸들러가 폼 데이터를 수신합니다.
// - 시트에 저장하거나 이메일 전송 로직을 추가하세요.
function doPost(e) {
try {
var data = e.parameter || {}
// TODO: 시트에 저장 예시
// var ss = SpreadsheetApp.getActiveSpreadsheet()
// var sheet = ss.getSheetByName('Responses') || ss.insertSheet('Responses')
// sheet.appendRow([new Date(), JSON.stringify(data)])
return ContentService.createTextOutput(JSON.stringify({ ok: true }))
.setMimeType(ContentService.MimeType.JSON)
} catch (err) {
return ContentService.createTextOutput(JSON.stringify({ ok: false, error: String(err) }))
.setMimeType(ContentService.MimeType.JSON)
}
const code = `/**
* Google Apps Script Web App for form submissions
* - Deploy as Web App and set URL as form action if needed.
*/
function doPost(e){
// TODO: handle submission to Google Sheets
return ContentService.createTextOutput('OK')
}
`
const readme = `README (Google Sheets Apps Script 템플릿)
1) Google Drive에서 새 스크립트(Apps Script) 프로젝트를 생성합니다.
2) Code.gs 파일 내용을 붙여넣습니다.
3) Deploy > New deployment > Web app 으로 배포합니다.
- Execute as: Me
- Who has access: Anyone
4) 배포 URL을 복사하여 빌더의 Form action URL에 넣습니다.
5) 필요한 경우 doPost에서 스프레드시트 저장 로직을 추가하세요.
`
extras['sheets/Code.gs'] = te.encode(code)
extras['sheets/README.txt'] = te.encode(readme)
const readme = `Google Sheets Apps Script Template\n\n1) Apps Script에서 새 프로젝트를 만들고 아래 Code.gs를 붙여넣으세요.\n2) 배포 > 웹 앱으로 배포 후 URL을 복사해 사용하세요.`
out['sheets/Code.gs'] = toBytes(code)
out['sheets/README.txt'] = toBytes(readme)
}
return extras
return out
}
+9 -9
View File
@@ -13,17 +13,17 @@ function makePage(): Page {
})
}
describe('Exporter - 폰트 최적화', () => {
it('head에 폰트 preconnect 링크가 포함된다(googleapis/gstatic)', () => {
const out = exportPage(makePage())
const html = out.html
expect(html).toMatch(/<link rel="preconnect" href="https:\/\/fonts\.googleapis\.com">/)
expect(html).toMatch(/<link rel="preconnect" href="https:\/\/fonts\.gstatic\.com" crossorigin>/)
describe('폰트 최적화', () => {
it('head에 Google Fonts preconnect 링크가 포함된다', () => {
const page = makePage()
const out = exportPage(page)
expect(out.html).toContain('<link rel="preconnect" href="https://fonts.googleapis.com"')
expect(out.html).toContain('<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin')
})
it('CSS에 system-ui 폴백이 포함된다', () => {
const out = exportPage(makePage())
const css = out.css
expect(css).toMatch(/font-family:[^;]*system-ui/i)
const page = makePage()
const out = exportPage(page)
expect(out.css).toMatch(/font-family:[^;]*system-ui/i)
})
})
+2 -5
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" width="1200" height="675" />
<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(heading)}" loading="lazy" decoding="async" />
</div>
</div>
</section>
@@ -254,9 +254,7 @@ function buildHead(page: Page) {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="canonical" href="/" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="icon" href="/favicon.ico" />
<meta name="theme-color" content="${page.theme.primaryColor}" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<title>${escapeHtml(page.seo.title)}</title>
<meta name="description" content="${escapeHtml(page.seo.description)}" />
<meta property="og:title" content="${escapeHtml(page.seo.title)}" />
@@ -339,7 +337,6 @@ export function exportPage(page: Page, opts?: ExportOptions): Exported {
<html lang="${escapeHtml(page.locale)}">
<head>
${buildHead(page)}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
</head>
<body>
-21
View File
@@ -1,21 +0,0 @@
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: 'Head Links',
locale: 'en',
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
sections: [],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 't', description: 'd' },
})
}
describe('Exporter - head 링크 토큰', () => {
it('site.webmanifest 링크를 포함한다', () => {
const out = exportPage(makePage())
expect(out.html).toMatch(/<link rel="manifest" href="\/site\.webmanifest"\s*\/>/)
})
})
+16 -21
View File
@@ -2,36 +2,31 @@ import { describe, it, expect } from 'vitest'
import { pageSchema, type Page } from '@/lib/schema/page'
import { buildExtrasForPage } from '@/lib/exporter/extras'
function makePage(overrides: Partial<Page> = {}): Page {
const base: Page = pageSchema.parse({
title: 'My Landing',
function makePage(): Page {
return pageSchema.parse({
title: 'Auto Extras',
locale: 'en',
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
sections: [],
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 'SEO Title', description: 'desc' },
seo: { title: 't', description: 'd' },
})
return { ...base, ...overrides }
}
describe('extras 자동 생성: site.webmanifest / robots.txt', () => {
it('Page에서 파생된 site.webmanifest JSON과 robots.txt를 extras에 포함다', async () => {
const page = makePage({ title: 'Awesome App', theme: { primaryColor: '#123456', fontFamily: 'Inter' } })
describe('extras 자동 생성', () => {
it('robots.txt와 site.webmanifest extras에 포함다', () => {
const page = makePage()
const extras = buildExtrasForPage(page)
const keys = Object.keys(extras)
expect(keys).toContain('robots.txt')
expect(keys).toContain('site.webmanifest')
// robots.txt 존재 및 베이스라인 확인
expect(Object.keys(extras)).toContain('robots.txt')
const robots = new TextDecoder().decode(extras['robots.txt'])
expect(robots).toMatch(/User-agent: \*/)
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
expect(robots).toContain('User-agent: *')
// manifest 존재 및 필수 키 확인
expect(Object.keys(extras)).toContain('site.webmanifest')
const manifestStr = new TextDecoder().decode(extras['site.webmanifest'])
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
const manifest = JSON.parse(manifestStr)
expect(manifest.name).toBe('Awesome App')
expect(manifest.short_name.length).toBeGreaterThan(0)
expect(manifest.start_url).toBe('/')
expect(manifest.display).toBe('standalone')
expect(manifest.theme_color).toBe('#123456')
expect(manifest.start_url).toBeDefined()
expect(manifest.display).toBeDefined()
})
})
@@ -1,31 +0,0 @@
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]+"/)
})
})
-47
View File
@@ -1,47 +0,0 @@
import { describe, it, expect } from 'vitest'
import { buildZip } from '@/lib/exporter/zip'
import { exportPage } from '@/lib/exporter/html'
import { pageSchema, type Page } from '@/lib/schema/page'
import { buildExtrasForPage } from '@/lib/exporter/extras'
function makePageNoAction(): Page {
return pageSchema.parse({
title: 'Sheets Tpl',
locale: 'en',
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
form: { actionUrl: '', fields: [ { type: 'text', name: 'email', label: 'Email', required: true } ], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 't', description: 'd' },
})
}
function makePageWithAction(): Page {
return pageSchema.parse({
title: 'Sheets Off',
locale: 'en',
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
form: { actionUrl: 'https://example.com/submit', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 't', description: 'd' },
})
}
describe('Sheets 템플릿 Export', () => {
it('actionUrl 미지정 시 extras에 Sheets 템플릿 파일을 포함한다', async () => {
const page = makePageNoAction()
const extras = buildExtrasForPage(page)
expect(Object.keys(extras)).toContain('sheets/Code.gs')
expect(Object.keys(extras)).toContain('sheets/README.txt')
const out = exportPage(page)
const zipBytes = await buildZip({ html: out.html, css: out.css, js: out.js, assets: {}, extras })
expect(zipBytes.byteLength).toBeGreaterThan(0)
})
it('actionUrl 지정 시 extras에는 Sheets 템플릿이 포함되지 않는다', () => {
const page = makePageWithAction()
const extras = buildExtrasForPage(page)
expect(Object.keys(extras)).not.toContain('sheets/Code.gs')
expect(Object.keys(extras)).not.toContain('sheets/README.txt')
})
})
+20 -21
View File
@@ -1,40 +1,39 @@
import { describe, it, expect } from 'vitest'
import JSZip from 'jszip'
import { exportPage } from '@/lib/exporter/html'
import { buildZip } from '@/lib/exporter/zip'
import { buildExtrasForPage } from '@/lib/exporter/extras'
import { exportPage } from '@/lib/exporter/html'
import { pageSchema, type Page } from '@/lib/schema/page'
import { buildExtrasForPage } from '@/lib/exporter/extras'
function makePage(): Page {
return pageSchema.parse({
title: 'Phase5',
title: 'ZIP Phase5',
locale: 'en',
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
sections: [],
sections: [ { type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'https://img/h.png' } } ],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
seo: { title: 't', description: 'd' },
})
}
describe('Export ZIP 검증 강화 5차: extras MIME/내용 검증', () => {
it('robots.txt는 텍스트이고, site.webmanifest는 유효한 JSON이다', async () => {
describe('ZIP 검증 Phase5', () => {
it('robots.txt 베이스라인과 site.webmanifest JSON 파싱 검증', async () => {
const page = makePage()
const out = exportPage(page)
const extras = buildExtrasForPage(page)
// baseline robots
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
expect(robots).toContain('User-agent: *')
// manifest JSON parseable
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
const manifest = JSON.parse(manifestStr)
expect(manifest && typeof manifest === 'object').toBe(true)
expect(manifest.start_url).toBeDefined()
expect(manifest.display).toBeDefined()
// ZIP build should succeed
const out = exportPage(page)
const zipBytes = await buildZip({ html: out.html, css: out.css, js: out.js, assets: {}, extras })
const zip = await JSZip.loadAsync(zipBytes)
// robots.txt 존재 및 텍스트 확인
expect(Object.keys(zip.files)).toContain('robots.txt')
const robots = await zip.files['robots.txt'].async('string')
expect(robots).toMatch(/User-agent: \*/) // baseline
// site.webmanifest 존재 및 JSON 파싱 가능
expect(Object.keys(zip.files)).toContain('site.webmanifest')
const manifestStr = await zip.files['site.webmanifest'].async('string')
const parsed = JSON.parse(manifestStr)
expect(parsed.start_url).toBe('/')
expect(parsed.display).toBe('standalone')
expect(zipBytes.byteLength).toBeGreaterThan(0)
})
})