feat: 카드뉴스 포스트(관리자 admin/, /v1/card API, 피드 이미지 슬라이드), 인스타 홍보 기획 문서
This commit is contained in:
1 parent
96cbd19c61
commit
739a8c59eb
107 files changed
+17684
-19
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import type { Copy } from './templates'
|
||||
|
||||
/** 고친 문구를 주소에 싣는 꼴 (/render?copy=...). npm run card --copy 도 같은 꼴을 쓴다 */
|
||||
export function encodeCopy(copy: Copy) {
|
||||
const bytes = new TextEncoder().encode(JSON.stringify(copy))
|
||||
return btoa(String.fromCharCode(...bytes)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
||||
}
|
||||
|
||||
export function decodeCopy(value: string | null): Copy {
|
||||
if (!value) return {}
|
||||
try {
|
||||
const bin = atob(value.replace(/-/g, '+').replace(/_/g, '/'))
|
||||
return JSON.parse(new TextDecoder().decode(Uint8Array.from(bin, (c) => c.charCodeAt(0))))
|
||||
} catch (e) {
|
||||
console.warn('copy 값을 읽지 못해 기본 문구로 그립니다', e)
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
/** 이미지가 다 그려지고 글꼴이 다 받아진 뒤 */
|
||||
export async function whenPainted(root: HTMLElement) {
|
||||
await document.fonts.ready
|
||||
await Promise.all(
|
||||
Array.from(root.querySelectorAll('img'), (img) => (img.complete ? Promise.resolve() : img.decode().catch(() => undefined))),
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user