63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import type { Page } from '@/lib/schema/page'
|
|
|
|
// Sheets 템플릿 등 ZIP 루트/서브 경로에 포함할 추가 파일(extras)을 구성한다.
|
|
// - actionUrl이 비어있을 때만 Google Apps Script 템플릿을 포함한다.
|
|
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)
|
|
// - 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 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)
|
|
}
|
|
|
|
return extras
|
|
}
|