diff --git a/lib/exporter/extras.ts b/lib/exporter/extras.ts index a29b7fa..e112772 100644 --- a/lib/exporter/extras.ts +++ b/lib/exporter/extras.ts @@ -6,6 +6,24 @@ export function buildExtrasForPage(page: Page): Record { const extras: Record = {} const te = new TextEncoder() + // Always provide a baseline robots.txt + const robots = `User-agent: *\nDisallow:` + extras['robots.txt'] = te.encode(robots) + + // 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', + } + extras['site.webmanifest'] = te.encode(JSON.stringify(manifest)) + } catch {} + const hasAction = !!(page.form?.actionUrl && page.form.actionUrl.trim().length > 0) if (!hasAction) { const code = `// Google Apps Script (Code.gs) diff --git a/lib/exporter/manifest.robots.auto.test.ts b/lib/exporter/manifest.robots.auto.test.ts new file mode 100644 index 0000000..faeeee4 --- /dev/null +++ b/lib/exporter/manifest.robots.auto.test.ts @@ -0,0 +1,37 @@ +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 { + const base: Page = pageSchema.parse({ + title: 'My Landing', + locale: 'en', + theme: { primaryColor: '#2563eb', fontFamily: 'Inter' }, + sections: [], + form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } }, + seo: { title: 'SEO Title', description: 'desc' }, + }) + 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' } }) + const extras = buildExtrasForPage(page) + + // robots.txt 존재 및 베이스라인 확인 + expect(Object.keys(extras)).toContain('robots.txt') + const robots = new TextDecoder().decode(extras['robots.txt']) + expect(robots).toMatch(/User-agent: \*/) + + // manifest 존재 및 필수 키 확인 + expect(Object.keys(extras)).toContain('site.webmanifest') + const manifestStr = new TextDecoder().decode(extras['site.webmanifest']) + 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') + }) +})