Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a9a7939b2 | |||
| 894acbb6a1 | |||
| 899a1ba1a6 | |||
| f385966f87 | |||
| c4d46a5de3 | |||
| 2caffe9950 | |||
| 8757809928 | |||
| 39c64e3acd | |||
| df5786e418 | |||
| 76889080e8 | |||
| 68c8c8ff15 | |||
| 9b8fbd6360 | |||
| 8ada2d1947 | |||
| 1a405a54fa | |||
| 5c23cf3873 | |||
| cc2b3039a3 | |||
| 0561c5d63c | |||
| e6c897a863 | |||
| 39318dd40d | |||
| be80f9339b | |||
| df41aac2b1 | |||
| a620ff970a | |||
| 524abda49c | |||
| fe62656d37 | |||
| 8ad3a9e677 | |||
| e9a87773ea | |||
| 678b081364 | |||
| 46a9c5c83d | |||
| 6c86e1cf85 | |||
| a16541e90d | |||
| aaea43f2cc | |||
| 3f7bf3f1c8 | |||
| bc29faf60c | |||
| 4b9627d4ee | |||
| 26a3b43d28 | |||
| 6ff27295e6 |
@@ -20,22 +20,15 @@ jobs:
|
|||||||
echo "CI_TOKEN not set; skipping labeling"; exit 0; fi
|
echo "CI_TOKEN not set; skipping labeling"; exit 0; fi
|
||||||
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||||
echo "Resolving label id for 'automerge' in $OWNER/$NAME"
|
echo "Resolving existing label id for 'automerge' in $OWNER/$NAME (no creation)"
|
||||||
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || true
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || true
|
||||||
# Robust parse without jq: find the id preceding name "automerge"
|
# Extract all ids whose name == automerge, prefer the smallest id (oldest)
|
||||||
LID=$(tr '\n' ' ' < /tmp/labels.json | grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | head -n1 | sed -E 's/.*"id":([0-9]+).*/\1/' || true)
|
LID=$(tr '\n' ' ' < /tmp/labels.json | \
|
||||||
|
grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | \
|
||||||
|
sed -E 's/.*"id":([0-9]+).*/\1/' | sort -n | head -n1 || true)
|
||||||
if [ -z "${LID:-}" ]; then
|
if [ -z "${LID:-}" ]; then
|
||||||
echo "Label 'automerge' not found. Creating..."
|
echo "No existing 'automerge' label found; skipping labeling"; exit 0; fi
|
||||||
curl -sS -o /tmp/create_label.json -X POST \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-H "Authorization: token ${CI_TOKEN}" \
|
|
||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels" \
|
|
||||||
-d '{"name":"automerge","color":"#0ea5e9"}'
|
|
||||||
LID=$(tr '\n' ' ' < /tmp/create_label.json | sed -E 's/.*"id":([0-9]+).*/\1/' | head -n1 || true)
|
|
||||||
fi
|
|
||||||
if [ -z "${LID:-}" ]; then
|
|
||||||
echo "Failed to resolve or create label id; skipping"; exit 0; fi
|
|
||||||
echo "Labeling PR #$PR_NUMBER with id $LID"
|
echo "Labeling PR #$PR_NUMBER with id $LID"
|
||||||
curl -sS -X POST \
|
curl -sS -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|||||||
@@ -55,19 +55,12 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "${PR_NUMBER:-}" ]; then
|
if [ -n "${PR_NUMBER:-}" ]; then
|
||||||
echo "Resolving label id for 'automerge' in $OWNER/$NAME"
|
echo "Resolving existing label id for 'automerge' in $OWNER/$NAME (no creation)"
|
||||||
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels"
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || true
|
||||||
LID=$(awk 'BEGIN{RS=","} /"name":"automerge"/ {if (match($0,/"id":([0-9]+)/,m)) {print m[1]; exit}}' /tmp/labels.json || true)
|
LID=$(tr '\n' ' ' < /tmp/labels.json | \
|
||||||
if [ -z "${LID:-}" ]; then
|
grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | \
|
||||||
echo "Label 'automerge' not found. Creating..."
|
sed -E 's/.*"id":([0-9]+).*/\1/' | sort -n | head -n1 || true)
|
||||||
curl -sS -o /tmp/create_label.json -X POST \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-H "Authorization: token ${CI_TOKEN}" \
|
|
||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels" \
|
|
||||||
-d '{"name":"automerge","color":"#0ea5e9"}'
|
|
||||||
LID=$(sed -n 's/.*"id":\([0-9]*\).*/\1/p' /tmp/create_label.json | head -n1 || true)
|
|
||||||
fi
|
|
||||||
if [ -n "${LID:-}" ]; then
|
if [ -n "${LID:-}" ]; then
|
||||||
echo "Adding 'automerge' (id=$LID) label to PR #$PR_NUMBER"
|
echo "Adding 'automerge' (id=$LID) label to PR #$PR_NUMBER"
|
||||||
curl -sS -X POST \
|
curl -sS -X POST \
|
||||||
@@ -76,7 +69,7 @@ jobs:
|
|||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
||||||
-d '{"labels":['"${LID}"']}' || true
|
-d '{"labels":['"${LID}"']}' || true
|
||||||
else
|
else
|
||||||
echo "Failed to resolve label id; skipping label add"
|
echo "No existing 'automerge' label found; skipping label add"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "PR number could not be determined; skipping label add"
|
echo "PR number could not be determined; skipping label add"
|
||||||
|
|||||||
@@ -39,3 +39,4 @@ yarn-error.log*
|
|||||||
# typescript
|
# typescript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
MAIN_PLAN.md
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { pageSchema, type Page } from '@/lib/schema/page'
|
|||||||
import { exportPage } from '@/lib/exporter/html'
|
import { exportPage } from '@/lib/exporter/html'
|
||||||
import { AssetManager } from '@/lib/assets/assetManager'
|
import { AssetManager } from '@/lib/assets/assetManager'
|
||||||
import { buildZip } from '@/lib/exporter/zip'
|
import { buildZip } from '@/lib/exporter/zip'
|
||||||
|
import { buildExtrasForPage } from '@/lib/exporter/extras'
|
||||||
import type { Section } from '@/lib/state/store'
|
import type { Section } from '@/lib/state/store'
|
||||||
import { createFormStore, type FormState } from '@/lib/state/formStore'
|
import { createFormStore, type FormState } from '@/lib/state/formStore'
|
||||||
import FormBuilderPanel from '@/components/FormBuilderPanel'
|
import FormBuilderPanel from '@/components/FormBuilderPanel'
|
||||||
@@ -47,6 +48,13 @@ export default function BuilderClientPage() {
|
|||||||
const [ogImage, setOgImage] = useState<string>('')
|
const [ogImage, setOgImage] = useState<string>('')
|
||||||
const [ga4MeasurementId, setGa4MeasurementId] = useState<string>('')
|
const [ga4MeasurementId, setGa4MeasurementId] = useState<string>('')
|
||||||
const [metaPixelId, setMetaPixelId] = useState<string>('')
|
const [metaPixelId, setMetaPixelId] = useState<string>('')
|
||||||
|
// Export Options (manifest/robots overrides)
|
||||||
|
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'>(() => {
|
const [viewport, setViewport] = useState<'desktop' | 'mobile'>(() => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
try {
|
try {
|
||||||
@@ -185,7 +193,20 @@ export default function BuilderClientPage() {
|
|||||||
}, [pageData, am])
|
}, [pageData, am])
|
||||||
|
|
||||||
const doExport = useCallback(async () => {
|
const doExport = useCallback(async () => {
|
||||||
const valid = pageSchema.parse(pageData)
|
let valid = pageData as Page
|
||||||
|
try {
|
||||||
|
valid = pageSchema.parse(pageData)
|
||||||
|
} catch {
|
||||||
|
const fixed: Page = {
|
||||||
|
...pageData,
|
||||||
|
form: {
|
||||||
|
actionUrl: pageData.form?.actionUrl ?? '',
|
||||||
|
fields: pageData.form?.fields ?? [],
|
||||||
|
spamProtection: pageData.form?.spamProtection ?? { honeypotFieldName: '_hp', minSubmitSeconds: 2 },
|
||||||
|
},
|
||||||
|
} as Page
|
||||||
|
valid = pageSchema.parse(fixed)
|
||||||
|
}
|
||||||
const exported = exportPage(valid, { assetManager: am ?? undefined })
|
const exported = exportPage(valid, { assetManager: am ?? undefined })
|
||||||
try {
|
try {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
@@ -196,9 +217,30 @@ export default function BuilderClientPage() {
|
|||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
const assets = am ? am.toZipStructure() : {}
|
const assets = am ? am.toZipStructure() : {}
|
||||||
const zipBytes = await buildZip({ html: exported.html, css: exported.css, js: exported.js, assets })
|
// 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
|
||||||
|
const robotsTextOverride = (() => {
|
||||||
|
const lines = (robotsDisallow || '').split(/\n+/).map((s) => s.trim()).filter((s) => s.length > 0)
|
||||||
|
if (lines.length === 0) return undefined
|
||||||
|
const disallowLines = lines.map((l) => (l.startsWith('Disallow:') ? l : `Disallow: ${l}`))
|
||||||
|
return `User-agent: *\n${disallowLines.join('\n')}`
|
||||||
|
})()
|
||||||
|
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)
|
download('landing.zip', zipBytes)
|
||||||
}, [pageData, am])
|
}, [pageData, am, manifestName, manifestShortName, manifestStartUrl, manifestDisplay, manifestThemeColor, robotsDisallow])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
@@ -261,6 +303,80 @@ export default function BuilderClientPage() {
|
|||||||
onSelect={(i) => setSelectedIndex(i)}
|
onSelect={(i) => setSelectedIndex(i)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<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">
|
||||||
|
<span className="sr-only">Manifest Name</span>
|
||||||
|
<input
|
||||||
|
id="ins-manifest-name"
|
||||||
|
aria-label="Manifest Name"
|
||||||
|
className="border rounded px-3 py-2 w-full"
|
||||||
|
value={manifestName}
|
||||||
|
onChange={(e) => setManifestName(e.target.value)}
|
||||||
|
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"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
right={
|
right={
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
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
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
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 → extras overrides', () => {
|
||||||
|
it('passes manifest.name and robots Disallow to buildExtrasForPage via buildZip extras', async () => {
|
||||||
|
render(<BuilderClientPage />)
|
||||||
|
|
||||||
|
const manifestName = 'My App Custom'
|
||||||
|
const robotsDisallow = '/private\n/tmp'
|
||||||
|
|
||||||
|
const nameInput = await screen.findByLabelText('Manifest Name')
|
||||||
|
fireEvent.change(nameInput, { target: { value: manifestName } })
|
||||||
|
|
||||||
|
const robotsInput = await screen.findByLabelText('Robots Disallow')
|
||||||
|
fireEvent.change(robotsInput, { target: { value: robotsDisallow } })
|
||||||
|
|
||||||
|
const exportBtn = await screen.findByRole('button', { name: 'builder.action.export' })
|
||||||
|
fireEvent.click(exportBtn)
|
||||||
|
|
||||||
|
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/)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { exportPage } from '@/lib/exporter/html'
|
||||||
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||||
|
|
||||||
|
function makePage(overrides: Partial<Page> = {}): Page {
|
||||||
|
const base: Page = {
|
||||||
|
title: 'CTA Edge',
|
||||||
|
locale: 'en',
|
||||||
|
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||||
|
sections: [
|
||||||
|
{ type: 'cta', props: { text: ' ', href: '#' } },
|
||||||
|
{ type: 'features', props: { items: ['One'] } },
|
||||||
|
] as Page['sections'],
|
||||||
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||||
|
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||||
|
seo: { title: 't', description: 'd' },
|
||||||
|
}
|
||||||
|
return pageSchema.parse({ ...base, ...overrides })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Exporter - CTA edge cases', () => {
|
||||||
|
it('drops CTA section when text is whitespace-only', () => {
|
||||||
|
const out = exportPage(makePage())
|
||||||
|
expect(out.html).not.toContain('<section class="cta"')
|
||||||
|
expect(out.html).not.toContain('<a class="btn-cta"')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders CTA when text is valid after trimming', () => {
|
||||||
|
const out = exportPage(makePage({ sections: [ { type: 'cta', props: { text: ' Buy Now ', href: '#' } } ] as Page['sections'] }))
|
||||||
|
expect(out.html).toContain('<a class="btn-cta" href="#">Buy Now</a>')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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',
|
||||||
|
locale: 'en',
|
||||||
|
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: 't', description: 'd' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('extras 오버라이드', () => {
|
||||||
|
it('robots.txt Disallow 오버라이드가 반영된다', () => {
|
||||||
|
const page = makePage()
|
||||||
|
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('manifest 필드 오버라이드(name/short_name/start_url/display/theme_color)가 반영된다', () => {
|
||||||
|
const page = makePage()
|
||||||
|
const extras = buildExtrasForPage(page, {
|
||||||
|
manifest: {
|
||||||
|
name: 'My App',
|
||||||
|
short_name: 'MyApp',
|
||||||
|
start_url: '/start',
|
||||||
|
display: 'minimal-ui',
|
||||||
|
theme_color: '#123abc',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
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('#123abc')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import type { Page } from '@/lib/schema/page'
|
||||||
|
|
||||||
|
export type ExtrasOverrides = {
|
||||||
|
robotsText?: string
|
||||||
|
manifest?: Partial<{
|
||||||
|
name: string
|
||||||
|
short_name: string
|
||||||
|
start_url: string
|
||||||
|
display: string
|
||||||
|
theme_color: string
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
||||||
|
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 out: Record<string, Uint8Array> = {}
|
||||||
|
|
||||||
|
// robots.txt
|
||||||
|
const robotsText = buildRobots(overrides?.robotsText)
|
||||||
|
out['robots.txt'] = toBytes(robotsText)
|
||||||
|
|
||||||
|
// site.webmanifest
|
||||||
|
const manifestBase = deriveManifest(page)
|
||||||
|
const manifestMerged = { ...manifestBase, ...(overrides?.manifest || {}) }
|
||||||
|
const manifestJson = JSON.stringify(manifestMerged, null, 2)
|
||||||
|
out['site.webmanifest'] = toBytes(manifestJson)
|
||||||
|
|
||||||
|
// Google Sheets 템플릿: actionUrl 미지정 시 포함
|
||||||
|
const action = page.form?.actionUrl?.trim()
|
||||||
|
const hasAction = !!(action && action.length > 0)
|
||||||
|
if (!hasAction) {
|
||||||
|
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 = `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 out
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
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: 'Font Opt',
|
||||||
|
locale: 'en',
|
||||||
|
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: 't', description: 'd' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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 page = makePage()
|
||||||
|
const out = exportPage(page)
|
||||||
|
expect(out.css).toMatch(/font-family:[^;]*system-ui/i)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -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(overrides: Partial<Page> = {}): Page {
|
||||||
|
const base: Page = {
|
||||||
|
title: 'Hero Edge',
|
||||||
|
locale: 'en',
|
||||||
|
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||||
|
sections: [
|
||||||
|
{ type: 'hero', props: { heading: 'Welcome', subheading: ' ', imageUrl: 'https://img.example/h.png' } },
|
||||||
|
] as Page['sections'],
|
||||||
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||||
|
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||||
|
seo: { title: 't', description: 'd' },
|
||||||
|
}
|
||||||
|
return pageSchema.parse({ ...base, ...overrides })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Exporter - hero edge cases', () => {
|
||||||
|
it('omits subheading when whitespace-only', () => {
|
||||||
|
const out = exportPage(makePage())
|
||||||
|
expect(out.html).toContain('<h1 id="hero-heading">Welcome</h1>')
|
||||||
|
expect(out.html).not.toMatch(/<div class="text">[\s\S]*<p>\s*<\/p>/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('trims subheading content', () => {
|
||||||
|
const out = exportPage(makePage({ sections: [ { type: 'hero', props: { heading: 'Welcome', subheading: ' Hello world ', imageUrl: 'https://img.example/h.png' } } ] as Page['sections'] }))
|
||||||
|
expect(out.html).toContain('<p>Hello world</p>')
|
||||||
|
})
|
||||||
|
})
|
||||||
+37
-15
@@ -5,7 +5,12 @@ export type Exported = { html: string; css: string; js: string }
|
|||||||
export type ExportOptions = { assetManager?: AssetManager }
|
export type ExportOptions = { assetManager?: AssetManager }
|
||||||
|
|
||||||
function renderFaq(section: { props: { items: Array<{ q: string; a: string }> } }) {
|
function renderFaq(section: { props: { items: Array<{ q: string; a: string }> } }) {
|
||||||
const items: Array<{ q: string; a: string }> = Array.isArray(section.props.items) ? section.props.items : []
|
const itemsRaw: Array<{ q: string; a: string }> = Array.isArray(section.props.items) ? section.props.items : []
|
||||||
|
const isBlank = (s: string | undefined | null) => !s || s.trim().length === 0
|
||||||
|
const items = itemsRaw
|
||||||
|
.map((it) => ({ q: (it.q || '').trim(), a: (it.a || '').trim() }))
|
||||||
|
// drop when both question and answer are blank
|
||||||
|
.filter((it) => !(isBlank(it.q) && isBlank(it.a)))
|
||||||
return `
|
return `
|
||||||
<section class="faq" aria-labelledby="faq-heading">
|
<section class="faq" aria-labelledby="faq-heading">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -27,7 +32,9 @@ function renderFaq(section: { props: { items: Array<{ q: string; a: string }> }
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderFeatures(section: { props: { items: string[] } }) {
|
function renderFeatures(section: { props: { items: string[] } }) {
|
||||||
const items: string[] = Array.isArray(section.props?.items) ? section.props.items : []
|
const items: string[] = (Array.isArray(section.props?.items) ? section.props.items : [])
|
||||||
|
.map((s) => String(s ?? '').trim())
|
||||||
|
.filter((s) => s.length > 0)
|
||||||
return `
|
return `
|
||||||
<section class="features" aria-labelledby="features-heading">
|
<section class="features" aria-labelledby="features-heading">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -41,7 +48,9 @@ function renderFeatures(section: { props: { items: string[] } }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderBenefits(section: { props: { items: string[] } }) {
|
function renderBenefits(section: { props: { items: string[] } }) {
|
||||||
const items: string[] = Array.isArray(section.props?.items) ? section.props.items : []
|
const items: string[] = (Array.isArray(section.props?.items) ? section.props.items : [])
|
||||||
|
.map((s) => String(s ?? '').trim())
|
||||||
|
.filter((s) => s.length > 0)
|
||||||
return `
|
return `
|
||||||
<section class="benefits" aria-labelledby="benefits-heading">
|
<section class="benefits" aria-labelledby="benefits-heading">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -55,9 +64,12 @@ function renderBenefits(section: { props: { items: string[] } }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderTestimonials(section: { props: { items: Array<{ author: string; quote: string }> } }) {
|
function renderTestimonials(section: { props: { items: Array<{ author: string; quote: string }> } }) {
|
||||||
const items: Array<{ author: string; quote: string }> = Array.isArray(section.props?.items)
|
const items: Array<{ author: string; quote: string }> = (Array.isArray(section.props?.items)
|
||||||
? section.props.items
|
? section.props.items
|
||||||
: []
|
: [])
|
||||||
|
.map((it) => ({ author: (it.author || '').trim(), quote: (it.quote || '').trim() }))
|
||||||
|
// drop when both are blank
|
||||||
|
.filter((it) => !(it.author.length === 0 && it.quote.length === 0))
|
||||||
return `
|
return `
|
||||||
<section class="testimonials" aria-labelledby="testimonials-heading">
|
<section class="testimonials" aria-labelledby="testimonials-heading">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -66,8 +78,8 @@ function renderTestimonials(section: { props: { items: Array<{ author: string; q
|
|||||||
.map(
|
.map(
|
||||||
(it) => `
|
(it) => `
|
||||||
<figure class="testimonial">
|
<figure class="testimonial">
|
||||||
<blockquote>“${escapeHtml(it.quote || '')}”</blockquote>
|
<blockquote>“${escapeHtml(it.quote)}”</blockquote>
|
||||||
<figcaption>— ${escapeHtml(it.author || '')}</figcaption>
|
${it.author.length > 0 ? `<figcaption>— ${escapeHtml(it.author)}</figcaption>` : ''}
|
||||||
</figure>`
|
</figure>`
|
||||||
)
|
)
|
||||||
.join('')}
|
.join('')}
|
||||||
@@ -77,7 +89,9 @@ function renderTestimonials(section: { props: { items: Array<{ author: string; q
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderCta(section: { props: { text: string; href?: string } }) {
|
function renderCta(section: { props: { text: string; href?: string } }) {
|
||||||
const { text, href } = section.props
|
const href = section.props.href
|
||||||
|
const text = (section.props.text || '').trim()
|
||||||
|
if (text.length === 0) return ''
|
||||||
return `
|
return `
|
||||||
<section class="cta" aria-labelledby="cta-heading">
|
<section class="cta" aria-labelledby="cta-heading">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -96,7 +110,9 @@ const escapeHtml = (s: string) =>
|
|||||||
.replaceAll('"', '"')
|
.replaceAll('"', '"')
|
||||||
|
|
||||||
function renderHero(section: { props: { heading: string; subheading?: string; imageUrl: string } }, opts?: ExportOptions) {
|
function renderHero(section: { props: { heading: string; subheading?: string; imageUrl: string } }, opts?: ExportOptions) {
|
||||||
const { heading, subheading } = section.props
|
const { heading } = section.props
|
||||||
|
const subheadingRaw = section.props.subheading
|
||||||
|
const subheading = subheadingRaw ? subheadingRaw.trim() : ''
|
||||||
const am = opts?.assetManager
|
const am = opts?.assetManager
|
||||||
const imageUrlRaw: string = section.props.imageUrl
|
const imageUrlRaw: string = section.props.imageUrl
|
||||||
const imageUrl = am ? am.rewriteUrl(imageUrlRaw) : imageUrlRaw
|
const imageUrl = am ? am.rewriteUrl(imageUrlRaw) : imageUrlRaw
|
||||||
@@ -105,10 +121,10 @@ function renderHero(section: { props: { heading: string; subheading?: string; im
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<h1 id="hero-heading">${escapeHtml(heading)}</h1>
|
<h1 id="hero-heading">${escapeHtml(heading)}</h1>
|
||||||
${subheading ? `<p>${escapeHtml(subheading)}</p>` : ''}
|
${subheading.length > 0 ? `<p>${escapeHtml(subheading)}</p>` : ''}
|
||||||
</div>
|
</div>
|
||||||
<div class="media">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -238,6 +254,9 @@ function buildHead(page: Page) {
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<link rel="canonical" href="/" />
|
<link rel="canonical" href="/" />
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
|
<link rel="manifest" href="/site.webmanifest" />
|
||||||
|
<meta name="theme-color" content="${escapeHtml(page.theme.primaryColor)}" />
|
||||||
<title>${escapeHtml(page.seo.title)}</title>
|
<title>${escapeHtml(page.seo.title)}</title>
|
||||||
<meta name="description" content="${escapeHtml(page.seo.description)}" />
|
<meta name="description" content="${escapeHtml(page.seo.description)}" />
|
||||||
<meta property="og:title" content="${escapeHtml(page.seo.title)}" />
|
<meta property="og:title" content="${escapeHtml(page.seo.title)}" />
|
||||||
@@ -262,15 +281,17 @@ function buildCss(page: Page) {
|
|||||||
button:focus, a:focus, input:focus, select:focus, textarea:focus{ outline: 3px solid #2563eb; outline-offset:2px }
|
button:focus, a:focus, input:focus, select:focus, textarea:focus{ outline: 3px solid #2563eb; outline-offset:2px }
|
||||||
.faq-list{ list-style:none; padding:0; margin:0 }
|
.faq-list{ list-style:none; padding:0; margin:0 }
|
||||||
.faq-item{ margin: .75rem 0 }
|
.faq-item{ margin: .75rem 0 }
|
||||||
.faq-q{ font-size: 1rem; font-weight:600; }
|
.faq-q{ font-size: 1rem; font-weight:600; overflow-wrap:anywhere }
|
||||||
.faq-a{ color:#334155 }
|
.faq-a{ color:#334155; overflow-wrap:anywhere }
|
||||||
.btn-cta{ background: var(--primary); color:#fff; padding:.75rem 1rem; border-radius:.5rem; display:inline-block; text-decoration:none }
|
.btn-cta{ background: var(--primary); color:#fff; padding:.75rem 1rem; border-radius:.5rem; display:inline-block; text-decoration:none }
|
||||||
.features{ background:#f8fafc }
|
.features{ background:#f8fafc }
|
||||||
.features-list{ list-style:none; padding:0; margin:0; display:grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem }
|
.features-list{ list-style:none; padding:0; margin:0; display:grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem }
|
||||||
.feature-item{ background:#fff; border:1px solid #e2e8f0; border-radius:.5rem; padding:.75rem }
|
.feature-item{ background:#fff; border:1px solid #e2e8f0; border-radius:.5rem; padding:.75rem; overflow-wrap:anywhere }
|
||||||
|
.benefits-list{ list-style:none; padding:0; margin:0 }
|
||||||
|
.benefit-item{ overflow-wrap:anywhere }
|
||||||
.testimonials{ background:#ffffff }
|
.testimonials{ background:#ffffff }
|
||||||
.testimonial{ border-left:4px solid var(--primary); padding:.5rem 1rem; margin: .75rem 0; background:#fefefe }
|
.testimonial{ border-left:4px solid var(--primary); padding:.5rem 1rem; margin: .75rem 0; background:#fefefe }
|
||||||
.testimonial blockquote{ margin:0; font-style:italic; color:#1f2937 }
|
.testimonial blockquote{ margin:0; font-style:italic; color:#1f2937; overflow-wrap:anywhere }
|
||||||
.testimonial figcaption{ color:#475569; margin-top:.25rem }
|
.testimonial figcaption{ color:#475569; margin-top:.25rem }
|
||||||
@media (max-width: 640px){ .container{ padding: 1rem } h1{ font-size: 1.5rem } }
|
@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 } a{ color:#93c5fd } a:hover{ text-decoration:underline } button{ background: var(--primary); color:#fff } .btn-cta{ background: var(--primary); color:#fff } .faq-a{ color:#cbd5e1 } }
|
@media (prefers-color-scheme: dark){ body{ color:#e5e7eb; background:#0b1020 } .feature-item{ background:#0f172a; border-color:#1f2937 } a{ color:#93c5fd } a:hover{ text-decoration:underline } button{ background: var(--primary); color:#fff } .btn-cta{ background: var(--primary); color:#fff } .faq-a{ color:#cbd5e1 } }
|
||||||
@@ -318,6 +339,7 @@ export function exportPage(page: Page, opts?: ExportOptions): Exported {
|
|||||||
<html lang="${escapeHtml(page.locale)}">
|
<html lang="${escapeHtml(page.locale)}">
|
||||||
<head>
|
<head>
|
||||||
${buildHead(page)}
|
${buildHead(page)}
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
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*\/>/)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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: 'Auto Extras',
|
||||||
|
locale: 'en',
|
||||||
|
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: 't', description: 'd' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
const robots = Buffer.from(extras['robots.txt']).toString('utf8')
|
||||||
|
expect(robots).toContain('User-agent: *')
|
||||||
|
|
||||||
|
const manifestStr = Buffer.from(extras['site.webmanifest']).toString('utf8')
|
||||||
|
const manifest = JSON.parse(manifestStr)
|
||||||
|
expect(manifest.start_url).toBeDefined()
|
||||||
|
expect(manifest.display).toBeDefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { exportPage } from '@/lib/exporter/html'
|
||||||
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||||
|
|
||||||
|
function makePage(overrides: Partial<Page> = {}): Page {
|
||||||
|
const base: Page = {
|
||||||
|
title: 'Edge',
|
||||||
|
locale: 'en',
|
||||||
|
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||||
|
sections: [
|
||||||
|
{ type: 'features', props: { items: ['One', ' ', ' ', 'Two'] } },
|
||||||
|
{ type: 'benefits', props: { items: ['A', ' ', ' ', 'B'] } },
|
||||||
|
{ type: 'faq', props: { items: [
|
||||||
|
{ q: ' ', a: ' ' },
|
||||||
|
{ q: 'Valid Q', a: ' ' },
|
||||||
|
{ q: 'Another', a: 'Answer' },
|
||||||
|
] } },
|
||||||
|
{ type: 'testimonials', props: { items: [
|
||||||
|
{ author: ' ', quote: ' ' },
|
||||||
|
{ author: 'Jane', quote: ' Great product ' },
|
||||||
|
] } },
|
||||||
|
] as Page['sections'],
|
||||||
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||||
|
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||||
|
seo: { title: 't', description: 'd' },
|
||||||
|
}
|
||||||
|
return pageSchema.parse({ ...base, ...overrides })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Exporter - sections edge cases', () => {
|
||||||
|
it('filters out whitespace-only items and keeps valid ones', () => {
|
||||||
|
const out = exportPage(makePage())
|
||||||
|
const html = out.html
|
||||||
|
|
||||||
|
// features: only One, Two
|
||||||
|
expect(html).toContain('<li class="feature-item">One</li>')
|
||||||
|
expect(html).toContain('<li class="feature-item">Two</li>')
|
||||||
|
expect(html).not.toMatch(/<li class="feature-item"><\/li>/)
|
||||||
|
|
||||||
|
// benefits: only A, B
|
||||||
|
expect(html).toContain('<li class="benefit-item">A</li>')
|
||||||
|
expect(html).toContain('<li class="benefit-item">B</li>')
|
||||||
|
|
||||||
|
// faq: drop fully empty, keep items even if answer empty when question is valid
|
||||||
|
expect(html).toContain('<h3 class="faq-q">Valid Q</h3>')
|
||||||
|
// testimonials: drop fully empty, keep trimmed quote
|
||||||
|
expect(html).toContain('<blockquote>“Great product”</blockquote>')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('adds word-break tokens to avoid overflow for long words', () => {
|
||||||
|
const out = exportPage(makePage())
|
||||||
|
const css = out.css
|
||||||
|
expect(css).toMatch(/\.feature-item\{[\s\S]*(?:word-break:break-word|overflow-wrap:anywhere)/i)
|
||||||
|
expect(css).toMatch(/\.benefit-item\{[\s\S]*(?:word-break:break-word|overflow-wrap:anywhere)/i)
|
||||||
|
expect(css).toMatch(/\.testimonial blockquote\{[\s\S]*(?:word-break:break-word|overflow-wrap:anywhere)/i)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { exportPage } from '@/lib/exporter/html'
|
||||||
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||||
|
|
||||||
|
function makePage(overrides: Partial<Page> = {}): Page {
|
||||||
|
const base: Page = {
|
||||||
|
title: 'Edge P3',
|
||||||
|
locale: 'en',
|
||||||
|
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||||
|
sections: [
|
||||||
|
{ type: 'faq', props: { items: [ { q: 'VeryVeryVeryVeryVeryLongWordWithoutSpaces', a: 'AnotherSuperLongUnbreakableWord' } ] } },
|
||||||
|
{ type: 'testimonials', props: { items: [
|
||||||
|
{ author: ' ', quote: 'Great!' },
|
||||||
|
{ author: 'Alice', quote: 'Nice' },
|
||||||
|
] } },
|
||||||
|
] as Page['sections'],
|
||||||
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||||
|
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
||||||
|
seo: { title: 't', description: 'd' },
|
||||||
|
}
|
||||||
|
return pageSchema.parse({ ...base, ...overrides })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Exporter - phase3 edge cases', () => {
|
||||||
|
it('omits testimonial author line when author is blank', () => {
|
||||||
|
const out = exportPage(makePage())
|
||||||
|
const html = out.html
|
||||||
|
// First item author blank -> no figcaption for that blockquote
|
||||||
|
expect(html).toMatch(/<blockquote>“Great!\”<\/blockquote>[\s\S]*?<\/figure>/)
|
||||||
|
// Ensure the next item with author renders figcaption
|
||||||
|
expect(html).toMatch(/<figcaption>— Alice<\/figcaption>/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('adds word-break/overflow-wrap for FAQ q/a to avoid overflow', () => {
|
||||||
|
const out = exportPage(makePage())
|
||||||
|
const css = out.css
|
||||||
|
expect(css).toMatch(/\.faq-q\{[\s\S]*(?:overflow-wrap:anywhere|word-break:break-word)/i)
|
||||||
|
expect(css).toMatch(/\.faq-a\{[\s\S]*(?:overflow-wrap:anywhere|word-break:break-word)/i)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -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]+"/)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
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')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -5,6 +5,8 @@ export type BuildZipInput = {
|
|||||||
css: string
|
css: string
|
||||||
js: string
|
js: string
|
||||||
assets?: Record<string, Uint8Array>
|
assets?: Record<string, Uint8Array>
|
||||||
|
// root-level extra files like favicon.ico, site.webmanifest, robots.txt
|
||||||
|
extras?: Record<string, Uint8Array>
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildZip(input: BuildZipInput): Promise<Uint8Array> {
|
export async function buildZip(input: BuildZipInput): Promise<Uint8Array> {
|
||||||
@@ -19,6 +21,22 @@ export async function buildZip(input: BuildZipInput): Promise<Uint8Array> {
|
|||||||
zip.file(path, buf as unknown as Buffer)
|
zip.file(path, buf as unknown as Buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (input.extras) {
|
||||||
|
// validate manifest if present
|
||||||
|
if (Object.prototype.hasOwnProperty.call(input.extras, 'site.webmanifest')) {
|
||||||
|
try {
|
||||||
|
const manifestBytes = input.extras['site.webmanifest']
|
||||||
|
const manifestStr = Buffer.from(manifestBytes).toString('utf8')
|
||||||
|
JSON.parse(manifestStr)
|
||||||
|
} catch {
|
||||||
|
throw new Error('Invalid site.webmanifest JSON')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const [path, bytes] of Object.entries(input.extras)) {
|
||||||
|
const buf = Buffer.from(bytes)
|
||||||
|
zip.file(path, buf as unknown as Buffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
const content = await zip.generateAsync({ type: 'uint8array' })
|
const content = await zip.generateAsync({ type: 'uint8array' })
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import JSZip from 'jszip'
|
||||||
|
import { exportPage } from '@/lib/exporter/html'
|
||||||
|
import { buildZip } from '@/lib/exporter/zip'
|
||||||
|
import { AssetManager } from '@/lib/assets/assetManager'
|
||||||
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
||||||
|
|
||||||
|
function makePageWithLocalAsset(): { page: Page; am: AssetManager } {
|
||||||
|
const am = new AssetManager({ maxBytes: 1024 * 1024, allowedExts: ['png','svg','jpg','jpeg','webp'] })
|
||||||
|
// simulate adding a local image and referencing it by original name via local: prefix
|
||||||
|
const bytes = new Uint8Array([7,8,9])
|
||||||
|
// add as "hero.png"
|
||||||
|
am.add({ name: 'hero.png', type: 'image/png', bytes })
|
||||||
|
|
||||||
|
const base: Page = pageSchema.parse({
|
||||||
|
title: 'Integrated ZIP',
|
||||||
|
locale: 'en',
|
||||||
|
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
||||||
|
sections: [
|
||||||
|
{ type: 'hero', props: { heading: 'Hello', subheading: 'World', imageUrl: 'local:hero.png' } },
|
||||||
|
{ type: 'cta', props: { text: 'Go', href: '#' } },
|
||||||
|
],
|
||||||
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
||||||
|
analytics: { ga4MeasurementId: 'G-TEST', metaPixelId: '', customHeadHtml: '' },
|
||||||
|
seo: { title: 't', description: 'd' },
|
||||||
|
})
|
||||||
|
return { page: base, am }
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Export ZIP 통합 검증', () => {
|
||||||
|
it('exportPage 출력 + buildZip 결과에서 assets 경로/메타가 보존된다', async () => {
|
||||||
|
const { page, am } = makePageWithLocalAsset()
|
||||||
|
const out = exportPage(page, { assetManager: am })
|
||||||
|
const assets = am.toZipStructure()
|
||||||
|
const zipBytes = await buildZip({ html: out.html, css: out.css, js: out.js, assets })
|
||||||
|
|
||||||
|
const zip = await JSZip.loadAsync(zipBytes)
|
||||||
|
const names = Object.keys(zip.files)
|
||||||
|
// assets 파일이 존재해야 함
|
||||||
|
const assetKey = Object.keys(assets)[0]
|
||||||
|
expect(names).toContain(assetKey)
|
||||||
|
|
||||||
|
// index.html에 canonical/meta/ga4 스니펫 보존
|
||||||
|
const html = await zip.files['index.html'].async('string')
|
||||||
|
expect(html).toMatch(/<link rel="canonical" href="\//)
|
||||||
|
expect(html).toMatch(/<meta name="description" content="d"/)
|
||||||
|
expect(html).toMatch(/gtag\('config', 'G-TEST'\)/)
|
||||||
|
|
||||||
|
// hero 이미지가 재작성된 경로를 사용한다
|
||||||
|
const match = html.match(/<img[^>]*src="([^"]+)"/)
|
||||||
|
expect(match && match[1]).toBe(assetKey)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import JSZip from 'jszip'
|
||||||
|
import { buildZip } from '@/lib/exporter/zip'
|
||||||
|
|
||||||
|
describe('Export ZIP 메타 보존 검증', () => {
|
||||||
|
it('index.html의 SEO/OG/Analytics 메타가 그대로 보존된다', async () => {
|
||||||
|
const html = `<!DOCTYPE html><html><head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="canonical" href="/" />
|
||||||
|
<meta name="description" content="desc" />
|
||||||
|
<meta property="og:title" content="OT" />
|
||||||
|
<meta property="og:description" content="OD" />
|
||||||
|
<script>window.dataLayer=[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());</script>
|
||||||
|
</head><body>ok</body></html>`
|
||||||
|
const css = 'body{color:#222}'
|
||||||
|
const js = 'console.log("ok")'
|
||||||
|
|
||||||
|
const zipBytes = await buildZip({ html, css, js, assets: {} })
|
||||||
|
const zip = await JSZip.loadAsync(zipBytes)
|
||||||
|
const htmlContent = await zip.files['index.html'].async('string')
|
||||||
|
|
||||||
|
expect(htmlContent).toMatch(/<link rel="canonical" href="\//)
|
||||||
|
expect(htmlContent).toMatch(/<meta name="description" content="desc"/)
|
||||||
|
expect(htmlContent).toMatch(/<meta property="og:title" content="OT"/)
|
||||||
|
expect(htmlContent).toMatch(/<meta property="og:description" content="OD"/)
|
||||||
|
expect(htmlContent).toMatch(/window\.dataLayer=\[\];/)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import JSZip from 'jszip'
|
||||||
|
import { buildZip } from '@/lib/exporter/zip'
|
||||||
|
import type { BuildZipInput } from '@/lib/exporter/zip'
|
||||||
|
|
||||||
|
const TE = new TextEncoder()
|
||||||
|
|
||||||
|
describe('Export ZIP 검증 강화 4차: 루트 파일(favicon/manifest/robots)', () => {
|
||||||
|
it('루트 파일들을 포함한다: favicon.ico / site.webmanifest / robots.txt', async () => {
|
||||||
|
const manifest = {
|
||||||
|
name: 'Landing Builder',
|
||||||
|
short_name: 'LB',
|
||||||
|
start_url: '/',
|
||||||
|
display: 'standalone',
|
||||||
|
icons: [{ src: '/favicon.png', sizes: '512x512', type: 'image/png' }],
|
||||||
|
}
|
||||||
|
const input: BuildZipInput = {
|
||||||
|
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||||
|
css: 'body{color:#111}',
|
||||||
|
js: 'console.log("ok")',
|
||||||
|
assets: {},
|
||||||
|
extras: {
|
||||||
|
'favicon.ico': new Uint8Array([0, 1, 2, 3]),
|
||||||
|
'site.webmanifest': TE.encode(JSON.stringify(manifest)),
|
||||||
|
'robots.txt': TE.encode('User-agent: *\nDisallow:'),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const zipBytes = await buildZip(input)
|
||||||
|
|
||||||
|
const zip = await JSZip.loadAsync(zipBytes)
|
||||||
|
const names = Object.keys(zip.files)
|
||||||
|
expect(names).toContain('favicon.ico')
|
||||||
|
expect(names).toContain('site.webmanifest')
|
||||||
|
expect(names).toContain('robots.txt')
|
||||||
|
|
||||||
|
const robots = await zip.files['robots.txt'].async('string')
|
||||||
|
expect(robots).toMatch(/User-agent: \*/)
|
||||||
|
|
||||||
|
const parsed = JSON.parse(await zip.files['site.webmanifest'].async('string'))
|
||||||
|
expect(parsed.name).toBe('Landing Builder')
|
||||||
|
expect(parsed.icons[0].type).toBe('image/png')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('잘못된 manifest JSON이면 실패한다', async () => {
|
||||||
|
const badInput: BuildZipInput = {
|
||||||
|
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||||
|
css: 'body{color:#111}',
|
||||||
|
js: 'console.log("ok")',
|
||||||
|
extras: { 'site.webmanifest': TE.encode('{ invalid json') },
|
||||||
|
}
|
||||||
|
await expect(buildZip(badInput)).rejects.toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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 makePage(): Page {
|
||||||
|
return pageSchema.parse({
|
||||||
|
title: 'ZIP Phase5',
|
||||||
|
locale: 'en',
|
||||||
|
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: 't', description: 'd' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('ZIP 검증 Phase5', () => {
|
||||||
|
it('robots.txt 베이스라인과 site.webmanifest JSON 파싱 검증', async () => {
|
||||||
|
const page = makePage()
|
||||||
|
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 })
|
||||||
|
expect(zipBytes.byteLength).toBeGreaterThan(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import JSZip from 'jszip'
|
||||||
|
import { buildZip } from '@/lib/exporter/zip'
|
||||||
|
|
||||||
|
const TE = new TextEncoder()
|
||||||
|
|
||||||
|
describe('Export ZIP 검증 강화', () => {
|
||||||
|
it('assets가 비어있을 때 index.html/styles.css/app.js만 포함한다', async () => {
|
||||||
|
const zipBytes = await buildZip({
|
||||||
|
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||||
|
css: 'body{color:#111}',
|
||||||
|
js: 'console.log("ok")',
|
||||||
|
assets: {},
|
||||||
|
})
|
||||||
|
const zip = await JSZip.loadAsync(zipBytes)
|
||||||
|
const names = Object.keys(zip.files).sort()
|
||||||
|
expect(names).toEqual(['app.js','index.html','styles.css'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('assets가 있으면 모든 파일을 그대로 포함한다(서브폴더 포함)', async () => {
|
||||||
|
const assets = {
|
||||||
|
'assets/img/logo.png': new Uint8Array([0,1,2,3]),
|
||||||
|
'assets/svg/icon.svg': TE.encode('<svg></svg>'),
|
||||||
|
'assets/fonts/inter.woff2': new Uint8Array([4,5,6]),
|
||||||
|
}
|
||||||
|
const zipBytes = await buildZip({
|
||||||
|
html: '<!DOCTYPE html><html><head><title>a</title></head><body>ok</body></html>',
|
||||||
|
css: 'body{color:#111}',
|
||||||
|
js: 'console.log("ok")',
|
||||||
|
assets,
|
||||||
|
})
|
||||||
|
const zip = await JSZip.loadAsync(zipBytes)
|
||||||
|
const names = Object.keys(zip.files)
|
||||||
|
expect(names).toContain('index.html')
|
||||||
|
expect(names).toContain('styles.css')
|
||||||
|
expect(names).toContain('app.js')
|
||||||
|
expect(names).toContain('assets/img/logo.png')
|
||||||
|
expect(names).toContain('assets/svg/icon.svg')
|
||||||
|
expect(names).toContain('assets/fonts/inter.woff2')
|
||||||
|
|
||||||
|
const logo = await zip.files['assets/img/logo.png'].async('uint8array')
|
||||||
|
expect(Array.from(logo)).toEqual([0,1,2,3])
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user