@@ -3,16 +3,12 @@ import { existsSync } from "node:fs";
33import { mkdir , readdir , readFile , writeFile } from "node:fs/promises" ;
44import path from "node:path" ;
55import pako from "pako" ;
6- import crypto from "node:crypto" ;
76
87const fontsPath = "./node_modules/@fontsource/m-plus-rounded-1c/files/" ;
98const cssPath = "./node_modules/@fontsource/m-plus-rounded-1c/" ;
10- const outPath = "./public/m-plus-rounded-1c-nohint/" ;
11- const outURLBase = "/m-plus-rounded-1c-nohint" ;
9+ const outPath = "./app/m-plus-rounded-1c-nohint/" ;
1210
1311const weights = [ 400 , 700 ] ;
14- const woffHashes = new Map < string , string > ( ) ;
15- const woff2Hashes = new Map < string , string > ( ) ;
1612
1713if ( existsSync ( outPath ) ) {
1814 console . log ( `Output directory ${ outPath } already exists.` ) ;
@@ -38,17 +34,8 @@ if (existsSync(outPath)) {
3834 kerning : true ,
3935 deflate : ( data ) => Array . from ( pako . deflate ( Uint8Array . from ( data ) ) ) ,
4036 } ) as Buffer ;
41- const woffHash = crypto
42- . createHash ( "sha256" )
43- . update ( woffBuffer )
44- . digest ( "hex" )
45- . slice ( 0 , 8 ) ;
46- woffHashes . set ( path . parse ( file ) . name , woffHash ) ;
47- const outFileName = path . parse ( file ) . name + `-nohint-${ woffHash } .woff` ;
48- writeFile (
49- `./public/m-plus-rounded-1c-nohint/${ outFileName } ` ,
50- woffBuffer
51- ) . then ( ( ) => {
37+ const outFileName = path . parse ( file ) . name + `-nohint.woff` ;
38+ writeFile ( path . join ( outPath , outFileName ) , woffBuffer ) . then ( ( ) => {
5239 console . log ( `Processed ${ file } -> ${ outFileName } ` ) ;
5340 } ) ;
5441
@@ -57,17 +44,8 @@ if (existsSync(outPath)) {
5744 hinting : false ,
5845 kerning : true ,
5946 } ) as Buffer ;
60- const woff2Hash = crypto
61- . createHash ( "sha256" )
62- . update ( woff2Buffer )
63- . digest ( "hex" )
64- . slice ( 0 , 8 ) ;
65- woff2Hashes . set ( path . parse ( file ) . name , woff2Hash ) ;
66- const outFileName2 = path . parse ( file ) . name + `-nohint-${ woff2Hash } .woff2` ;
67- writeFile (
68- `./public/m-plus-rounded-1c-nohint/${ outFileName2 } ` ,
69- woff2Buffer
70- ) . then ( ( ) => {
47+ const outFileName2 = path . parse ( file ) . name + `-nohint.woff2` ;
48+ writeFile ( path . join ( outPath , outFileName2 ) , woff2Buffer ) . then ( ( ) => {
7149 console . log ( `Processed ${ file } -> ${ outFileName2 } ` ) ;
7250 } ) ;
7351 }
@@ -76,11 +54,7 @@ if (existsSync(outPath)) {
7654 let css = await readFile ( path . join ( cssPath , file ) , "utf-8" ) ;
7755 css = css . replace ( / u r l \( ( .+ ?) \) / g, ( match , p1 ) => {
7856 const parsedPath = path . parse ( p1 ) ;
79- const hash =
80- path . extname ( p1 ) === ".woff"
81- ? woffHashes . get ( parsedPath . name )
82- : woff2Hashes . get ( parsedPath . name ) ;
83- return `url(${ outURLBase } /${ parsedPath . name } -nohint-${ hash } ${ path . extname ( p1 ) } )` ;
57+ return `url(./${ parsedPath . name } -nohint${ parsedPath . ext } )` ;
8458 } ) ;
8559 css = css . replaceAll (
8660 "font-family: 'M PLUS Rounded 1c'" ,
0 commit comments