Merge pull request #16 from ClovertaTheTrilobita/dev

Deleted All Maple Mono CN for better performance
This commit is contained in:
ClovertaTheTrilobita 2026-04-16 02:44:33 +03:00 committed by GitHub
commit 8168e1fed2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 21 additions and 129 deletions

View file

@ -1,95 +0,0 @@
import fs from "fs";
import path from "path";
import Fontmin from "fontmin";
function getFiles(dir) {
const results = [];
const list = fs.readdirSync(dir);
for (const file of list) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
results.push(...getFiles(filePath));
} else {
results.push(filePath);
}
}
return results;
}
function scanDirectory(dir) {
let set = new Set();
const files = getFiles(dir);
for (const file of files) {
const ignoredExtensions = [
".ttf",
".otf",
".woff",
".woff2",
".eot",
".png",
".jpg",
".jpeg",
".webp",
".gif",
".ico",
".pdf",
];
if (ignoredExtensions.some((ext) => file.endsWith(ext))) continue;
try {
const content = fs.readFileSync(file, "utf8");
const currentSet = new Set(content);
set = new Set([...set, ...currentSet]);
} catch {
// 跳过二进制等不可读文件
}
}
return set;
}
function subsetFont(src, text) {
return new Promise((resolve, reject) => {
const fontmin = new Fontmin()
.src(src)
.use(
Fontmin.glyph({
text,
hinting: false,
})
)
.use(Fontmin.ttf2woff2())
.dest("public/fonts/subset");
fontmin.run((err) => {
if (err) return reject(err);
resolve();
});
});
}
async function main() {
const baseChars =
"首页文章标签关于作者评论发布于切换主题,。!?:“”‘’()《》【】、—…·-_/\\'\"()[]{}<>:;.!? ";
const scanned = Array.from(scanDirectory("src")).join("");
const chars = Array.from(new Set((scanned + baseChars).split(""))).join("");
await Promise.all([
subsetFont("public/fonts/MapleMono-CN-Regular.ttf", chars),
subsetFont("public/fonts/MapleMono-CN-Bold.ttf", chars),
subsetFont("public/fonts/MapleMono-CN-Italic.ttf", chars),
]);
console.log(`中文子集字体生成完成,共收集 ${chars.length} 个字符`);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});

View file

@ -9,8 +9,7 @@
"dev": "astro dev",
"preview": "astro preview",
"astro": "astro",
"subset-font": "node build/fontmin.js",
"build": "npm run subset-font && astro build"
"build": "astro build"
},
"dependencies": {
"@astrojs/rss": "^4.0.17",
@ -25,4 +24,4 @@
"@types/node": "^25.5.0",
"fontmin": "^1.1.1"
}
}
}

Binary file not shown.

Binary file not shown.

View file

@ -33,7 +33,7 @@ const pageTitle = t.home.title;
width="33"
height="33"
aria-hidden="true"
style="margin-left: -15px; margin-bottom: -5px; color:#3f50e5"
style="margin-left: 0px; margin-bottom: -5px; color:#3f50e5"
>
<path
d="M6.18 17.82a1.64 1.64 0 1 1 0 3.28 1.64 1.64 0 0 1 0-3.28ZM3 10.44v2.25c4.56 0 8.27 3.71 8.27 8.27h2.25C13.52 15.16 8.84 10.44 3 10.44Zm0-4.54v2.25c7.06 0 12.81 5.75 12.81 12.81h2.25C18.06 12.66 11.3 5.9 3 5.9Z"
@ -66,4 +66,8 @@ const pageTitle = t.home.title;
:global(.dark) .section-divider {
background: #7f8b97;
}
.page-title {
font-weight: 700;
}
</style>

View file

@ -2,30 +2,6 @@
@import url("https://unpkg.com/@fontsource/maple-mono@5.2.6/400-italic.css");
@import url("https://unpkg.com/@fontsource/maple-mono@5.2.6/700.css");
@font-face {
font-family: "Maple Mono CN";
src: url("/fonts/subset/MapleMono-CN-Regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Maple Mono CN";
src: url("/fonts/subset/MapleMono-CN-Italic.woff2") format("woff2");
font-weight: 400;
font-style: italic;
font-display: swap;
}
@font-face {
font-family: "Maple Mono CN";
src: url("/fonts/subset/MapleMono-CN-Bold.woff2") format("woff2");
font-weight: 700;
font-style: normal;
font-display: swap;
}
pre {
padding: 1rem;
border-radius: 0.5rem;
@ -57,7 +33,19 @@ article svg[id^="mermaid-"] {
}
html {
font-family: "Maple Mono", "Maple Mono CN", monospace;
/* font-family: "Maple Mono", "Maple Mono CN", monospace; */
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Oxygen,
Ubuntu,
Cantarell,
"Open Sans",
"Helvetica Neue",
sans-serif;
background-color: #ffffff;
color: #1f2328;
}
@ -101,7 +89,7 @@ html.dark body::after {
@media (max-width: 900px) {
body::after {
opacity: 0.1;
opacity: 0;
}
}
@ -113,10 +101,6 @@ html.dark body::after {
body {
font-size: 1rem;
}
body::after {
opacity: 0;
}
}