Skip to content

Commit 26aa0e2

Browse files
committed
ハッシュはwebpackに任せれば良かった
1 parent b4012c4 commit 26aa0e2

File tree

4 files changed

+9
-39
lines changed

4 files changed

+9
-39
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ next-env.d.ts
4545

4646

4747
/public/typescript/
48-
/public/m-plus-rounded-1c-nohint/
48+
/app/m-plus-rounded-1c-nohint/

app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { Metadata } from "next";
22
import "@fontsource-variable/inconsolata";
33
// import "@fontsource/m-plus-rounded-1c/400.css";
44
// import "@fontsource/m-plus-rounded-1c/700.css";
5-
import "@/../public/m-plus-rounded-1c-nohint/400.css";
6-
import "@/../public/m-plus-rounded-1c-nohint/700.css";
5+
import "@/m-plus-rounded-1c-nohint/400.css";
6+
import "@/m-plus-rounded-1c-nohint/700.css";
77
import "./globals.css";
88
import { Navbar } from "./navbar";
99
import { Sidebar } from "./sidebar";

public/_headers

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@
44
Cross-Origin-Embedder-Policy: require-corp
55
/typescript/*
66
Cache-Control: public,max-age=31536000,immutable
7-
/m-plus-rounded-1c-nohint/*.woff
8-
Cache-Control: public,max-age=31536000,immutable
9-
/m-plus-rounded-1c-nohint/*.woff2
10-
Cache-Control: public,max-age=31536000,immutable

scripts/removeHinting.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ import { existsSync } from "node:fs";
33
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
44
import path from "node:path";
55
import pako from "pako";
6-
import crypto from "node:crypto";
76

87
const fontsPath = "./node_modules/@fontsource/m-plus-rounded-1c/files/";
98
const 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

1311
const weights = [400, 700];
14-
const woffHashes = new Map<string, string>();
15-
const woff2Hashes = new Map<string, string>();
1612

1713
if (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(/url\((.+?)\)/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

Comments
 (0)