1
1
import fs from 'fs-extra' ;
2
2
import path from 'path' ;
3
+ import semver from 'semver' ;
3
4
import SVGIcons2SVGFont from 'svgicons2svgfont' ;
4
5
import svg2ttf from 'svg2ttf' ;
5
6
import ttf2woff2 from 'ttf2woff2' ;
@@ -74,10 +75,18 @@ function svgToSVGFont(fontName = "pinyin",src = "svg", dist = "./docs/pinyin.svg
74
75
fontStream . end ( ) ;
75
76
} ) ;
76
77
}
78
+ // Update version in docs/index.html
79
+ const pkg = fs . readJsonSync ( './package.json' ) ;
77
80
78
81
function svgFontToTTF ( src = "./docs/pinyin.svg" , dist = "./docs/pinyin.ttf" ) {
79
82
const svgFont = fs . readFileSync ( src , "utf8" ) ;
80
- const ttf = svg2ttf ( svgFont , { } ) ;
83
+ const version = semver . parse ( pkg . version ) ;
84
+ const ttf = svg2ttf ( svgFont , {
85
+ description : "Pinyin font specifically designed for the app 'Baby Copybook'." ,
86
+ copyright : "Copyright (c) 2024, Wang Chujiang <https://wangchujiang.com>" ,
87
+ url : "https://github.com/jaywcjlove/pinyin-font" ,
88
+ version : `Version ${ version . major } .${ version . minor } ` ,
89
+ } ) ;
81
90
const ttfBuf = Buffer . from ( ttf . buffer ) ;
82
91
fs . writeFileSync ( dist , ttfBuf ) ;
83
92
console . log ( `SUCCESS TTF font successfully created!\n ╰┈▶ ${ dist } ` ) ;
@@ -101,8 +110,6 @@ function ttfTowoff2(src = "./docs/pinyin.ttf", dist = "./docs/pinyin.woff2") {
101
110
svgFontToTTF ( "./docs/pinyin-regular.svg" , "./docs/pinyin-regular.ttf" ) ;
102
111
ttfTowoff2 ( "./docs/pinyin-regular.ttf" , "./docs/pinyin-regular.woff2" ) ;
103
112
104
- // Update version in docs/index.html
105
- const pkg = fs . readJsonSync ( './package.json' ) ;
106
113
const fileContent = fs . readFileSync ( './docs/index.html' , 'utf-8' ) ;
107
114
const updatedContent = fileContent . replace ( / < s u p > .* < \/ s u p > / g, `<sup>v${ pkg . version } </sup>` )
108
115
. replace ( / u r l \( ' .\/ p i n y i n - s t e p \. t t f .* ' \) \s / g, `url('./pinyin-step.ttf?v=${ pkg . version } ') ` )
0 commit comments