Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0561c5d63c | |||
| e6c897a863 |
@@ -6,6 +6,24 @@ export function buildExtrasForPage(page: Page): Record<string, Uint8Array> {
|
||||
const extras: Record<string, Uint8Array> = {}
|
||||
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)
|
||||
|
||||
@@ -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> = {}): 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')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
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 { pageSchema, type Page } from '@/lib/schema/page'
|
||||
|
||||
function makePage(): Page {
|
||||
return pageSchema.parse({
|
||||
title: 'Phase5',
|
||||
locale: 'en',
|
||||
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||
sections: [],
|
||||
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 () => {
|
||||
const page = makePage()
|
||||
const out = exportPage(page)
|
||||
const extras = buildExtrasForPage(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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user