feat: 그날 코디는 포스트 하나에 스타일 하나 — --style 로 스타일 태그(꾸안꾸·오피스룩…) 붙은 스냅만 고르고 제목 통일

This commit is contained in:
minaChoi committed 2026-10-26 11:09:04 +09:00
1 parent 814e64931d
commit a6251db762
6 files changed
+45 -21

No files matched your search

+5 -2
View File
@@ -34,6 +34,7 @@ let copy = flag('--copy')
const topic = flag('--topic')
const feedback = flag('--feedback')
const color = flag('--color')
const styleArg = flag('--style')
const outArg = flag('--out')
const take = (name) => args.includes(name) && args.splice(args.indexOf(name), 1).length > 0
let noImages = take('--no-images')
@@ -80,8 +81,10 @@ const outDir = resolve(outArg ?? `out/${day}`)
if (daily) {
if (template !== 'ootd') fail('--daily 는 ootd 템플릿에서만 써요.')
const { runDailyOotd, toCardOutfits } = await import('./daily-ootd.mjs')
const { outfits } = await runDailyOotd({ outDir })
copy = Buffer.from(JSON.stringify({ ...decode(copy), outfits: JSON.stringify(toCardOutfits(outfits)) })).toString('base64url')
// 포스트 하나는 스타일 하나: --style <casual|semi|formal|street|minimal>, 없으면 --copy 의 style, 그것도 없으면 꾸안꾸
const style = styleArg ?? decode(copy).style ?? 'minimal'
const { outfits } = await runDailyOotd({ outDir, style })
copy = Buffer.from(JSON.stringify({ ...decode(copy), style, outfits: JSON.stringify(toCardOutfits(outfits)) })).toString('base64url')
noImages = true
}
+14 -7
View File
@@ -52,12 +52,15 @@ function buildPrompt(persona, outfit, weather) {
.replace('{layering}', weather.layering)
}
/** @returns {Promise<{ weather: object, outfits: { persona: string, label: string, style: string, labels: string[], image: string, source: string, items: object[] }[] }>} */
export async function runDailyOotd({ outDir, log = console.log }) {
/** 포스트 하나는 스타일 하나(기본 꾸안꾸). 네 사람 모두 그 스타일 스냅에서 고르고 제목도 같은 스타일로 간다.
* @returns {Promise<{ weather: object, outfits: { persona: string, label: string, style: string, labels: string[], image: string, source: string, items: object[] }[] }>} */
export async function runDailyOotd({ outDir, style = 'minimal', log = console.log }) {
if (!spec.styles[style]) throw new Error(`스타일은 ${Object.keys(spec.styles).join(', ')} 중 하나예요: ${style}`)
const styleLabel = spec.styles[style].label
const weather = await weatherToday()
log(`오늘 ${weather.day}: 아침 ${weather.morningC}° · 낮 ${weather.maxC}° → 구간 ${weather.band}`)
log(`오늘 ${weather.day}: 아침 ${weather.morningC}° · 낮 ${weather.maxC}° → 구간 ${weather.band} · 스타일 ${styleLabel}`)
mkdirSync(outDir, { recursive: true })
const picks = await pickSnaps({ band: weather.band, outDir: join(outDir, 'snaps'), log })
const picks = await pickSnaps({ band: weather.band, style, outDir: join(outDir, 'snaps'), log })
const dailyDir = resolve('public/daily')
mkdirSync(dailyDir, { recursive: true })
const outfits = []
@@ -65,6 +68,8 @@ export async function runDailyOotd({ outDir, log = console.log }) {
const pick = picks[persona]
log(`${persona}: Claude가 옷 목록을 뽑는 중… (${pick.url})`)
const outfit = await extractOutfit(pick, persona, weather)
// 제목은 Claude 가 본 분위기가 아니라 포스트 스타일로 통일한다
outfit.style = styleLabel
const by = Object.fromEntries(outfit.items.map((it) => [it.slot, it]))
const labels = LABEL_ORDER.filter((s) => by[s]).map((s) => by[s].label)
log(` ${outfit.style}: ${labels.join(' · ')}`)
@@ -86,9 +91,11 @@ export const toCardOutfits = (outfits) => outfits.map(({ persona, label, style,
if (process.argv[1]?.endsWith('daily-ootd.mjs')) {
const args = process.argv.slice(2)
const outArg = args.includes('--out') ? args[args.indexOf('--out') + 1] : null
const flag = (n) => (args.includes(n) ? args[args.indexOf(n) + 1] : null)
const outArg = flag('--out')
const style = flag('--style') ?? 'minimal'
const day = new Date(Date.now() + 9 * 3600_000).toISOString().slice(0, 10)
const { outfits } = await runDailyOotd({ outDir: resolve(outArg ?? `out/${day}`) })
const copy = Buffer.from(JSON.stringify({ outfits: JSON.stringify(toCardOutfits(outfits)), theme: 'sky' })).toString('base64url')
const { outfits } = await runDailyOotd({ outDir: resolve(outArg ?? `out/${day}`), style })
const copy = Buffer.from(JSON.stringify({ outfits: JSON.stringify(toCardOutfits(outfits)), style, theme: 'sky' })).toString('base64url')
console.log(`카드 그리기: npm run card -- ootd --no-images --copy ${copy}`)
}
+19 -7
View File
@@ -32,6 +32,14 @@ const BAND = {
}
// 철 지난 스냅은 뺀다
const MAX_AGE_DAYS = 45
// 포스트 하나는 스타일 하나: 네 사람 모두 이 태그가 붙은 스냅에서 고른다 (image-prompts/ootd.json styles 의 id)
export const STYLE_TAGS = {
casual: ['데일리룩', '캐주얼룩', '캐주얼'],
semi: ['오피스룩', '출근룩', '비즈니스캐주얼'],
formal: ['정장', '수트', '포멀룩'],
street: ['스트릿', '스트릿룩', '스트릿패션'],
minimal: ['꾸안꾸', '미니멀룩', '미니멀'],
}
// 40대~ 는 단정한 코디 태그로 한 번 더 모은다
const MATURE_KEYWORDS = { WOMEN: ['오피스룩', '출근룩', '미니멀룩'], MEN: ['오피스룩', '댄디룩', '비즈니스캐주얼'] }
const MATURE_TAG = /오피스|출근|미니멀|클래식|단정|하객|댄디|비즈니스|포멀|꾸안꾸/
@@ -139,24 +147,28 @@ async function download(url, path) {
writeFileSync(path, Buffer.from(await res.arrayBuffer()))
}
/** 사람별로 스냅 하나씩: { f20: {...snap, files: { image, thumbs[] }}, ... } */
export async function pickSnaps({ band, outDir, pages = 2, log = console.log }) {
/** 사람별로 스냅 하나씩: { f20: {...snap, files: { image, thumbs[] }}, ... }. style 을 주면 네 사람 모두 그 스타일 태그가 붙은 스냅에서 고른다 */
export async function pickSnaps({ band, style, outDir, pages = 2, log = console.log }) {
mkdirSync(outDir, { recursive: true })
const rule = BAND[band] ?? BAND.mild
const styleTags = STYLE_TAGS[style] ?? []
const pool = new Map()
const add = (list) => list.forEach((s) => s.goodsNos.length >= 3 && !pool.has(s.id) && pool.set(s.id, s))
for (const tag of styleTags) add(await listSnaps({ tags: tag }, pages))
for (const tag of rule.tags) add(await listSnaps({ tags: tag }, pages))
for (const gender of ['WOMEN', 'MEN']) for (const kw of MATURE_KEYWORDS[gender]) add(await listSnaps({ keyword: kw }, 1))
log(`무신사 스냅 후보 ${pool.size}개 (구간 ${band}: #${rule.tags.join(' #')} + 단정 키워드). 상품 정보를 받아 거르는 중…`)
const hasStyle = (s) => styleTags.length === 0 || s.tags.some((t) => styleTags.some((st) => t.includes(st)))
log(`무신사 스냅 후보 ${pool.size}개 (구간 ${band}${styleTags.length ? ` · 스타일 #${styleTags.join(' #')} ${[...pool.values()].filter(hasStyle).length}개` : ''}). 상품 정보를 받아 거르는 중…`)
const picks = {}
const used = new Set()
// 40대~ 를 먼저 골라야 단정한 코디가 남는다. 좋아요 순으로 상품 정보를 받아 보며 맞는 첫 코디를 고른다
for (const persona of ['f40', 'm40', 'f20', 'm20']) {
const { gender } = PERSONAS[persona]
// 스타일 태그가 붙은 스냅을 먼저, 모자라면 나머지 (스타일 태그 없는 스냅은 뒤로)
const candidates = [...pool.values()]
.filter((s) => s.gender === gender && !used.has(s.id))
.sort((a, b) => score(b, persona) - score(a, persona))
.sort((a, b) => Number(hasStyle(b)) - Number(hasStyle(a)) || score(b, persona) - score(a, persona))
.slice(0, 25)
let best = null
for (const c of candidates) {
@@ -184,8 +196,8 @@ export async function pickSnaps({ band, outDir, pages = 2, log = console.log })
// 썸네일 없으면 상품명만 쓴다
}
}
picks[persona] = { ...best, files: { image, thumbs } }
log(` ${persona}: ${best.url} ♥${best.likes} #${best.tags.slice(0, 3).join(' #')} | ${best.goods.map((g) => g.name).join(' / ').slice(0, 90)}`)
picks[persona] = { ...best, styled: hasStyle(best), files: { image, thumbs } }
log(` ${persona}: ${best.url} ♥${best.likes}${styleTags.length && !hasStyle(best) ? ' (스타일 태그 없음, 대체)' : ''} #${best.tags.slice(0, 3).join(' #')} | ${best.goods.map((g) => g.name).join(' / ').slice(0, 90)}`)
}
writeFileSync(join(outDir, 'picks.json'), JSON.stringify(picks, null, 1))
return picks
@@ -196,5 +208,5 @@ if (process.argv[1]?.endsWith('snap.mjs')) {
const flag = (n) => (args.includes(n) ? args[args.indexOf(n) + 1] : null)
const band = flag('--band') ?? 'mild'
const outDir = flag('--out') ?? `out/${new Date(Date.now() + 9 * 3600_000).toISOString().slice(0, 10)}/snaps`
await pickSnaps({ band, outDir, pages: Number(flag('--pages') ?? 2) })
await pickSnaps({ band, style: flag('--style') ?? undefined, outDir, pages: Number(flag('--pages') ?? 2) })
}