29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
// templates/*.dc.html 의 /*PRETENDARD*/ 토큰을 Pretendard woff2 data URI 로 치환해
|
|
// 작업 디렉터리 루트에 최종 .dc.html 아트보드를 생성한다.
|
|
import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
const WEIGHTS = [
|
|
['Regular', 400],
|
|
['SemiBold', 600],
|
|
['Bold', 700],
|
|
];
|
|
|
|
const faces = WEIGHTS.map(([file, weight]) => {
|
|
const b64 = readFileSync(join('fonts', `Pretendard-${file}.subset.woff2`)).toString('base64');
|
|
return `@font-face{font-family:'Pretendard';font-style:normal;font-weight:${weight};font-display:swap;src:url(data:font/woff2;base64,${b64}) format('woff2');}`;
|
|
}).join('\n');
|
|
|
|
let count = 0;
|
|
for (const name of readdirSync('templates')) {
|
|
if (!name.endsWith('.dc.html')) continue;
|
|
const src = readFileSync(join('templates', name), 'utf8');
|
|
if (!src.includes('/*PRETENDARD*/')) {
|
|
console.error(`warn: ${name} 에 /*PRETENDARD*/ 토큰이 없습니다`);
|
|
}
|
|
writeFileSync(name, src.replace('/*PRETENDARD*/', faces), 'utf8');
|
|
count += 1;
|
|
console.log(`${name} — ${(readFileSync(name).length / 1024).toFixed(0)} KB`);
|
|
}
|
|
console.log(`${count} artboards built`);
|