修复了一些问题

This commit is contained in:
wisdgod
2025-01-23 12:34:56 +08:00
parent 3e304f53d4
commit 36b42e27de
73 changed files with 4918 additions and 2350 deletions

View File

@@ -3,6 +3,7 @@
const { minify: minifyHtml } = require('html-minifier-terser');
const { minify: minifyJs } = require('terser');
const CleanCSS = require('clean-css');
const MarkdownIt = require('markdown-it');
const fs = require('fs');
const path = require('path');
@@ -28,10 +29,75 @@ const cssOptions = {
// 处理文件
async function minifyFile(inputPath, outputPath) {
try {
const ext = path.extname(inputPath).toLowerCase();
const content = fs.readFileSync(inputPath, 'utf8');
let ext = path.extname(inputPath).toLowerCase();
if (ext === '.md') ext = '.html';
const filename = path.basename(inputPath);
let content = fs.readFileSync(inputPath, 'utf8');
let minified;
// 特殊处理 readme.html
if (filename.toLowerCase() === 'readme.md') {
const md = new MarkdownIt({
html: true,
linkify: true,
typographer: true
});
const readmeMdPath = path.join(__dirname, '..', 'README.md');
const markdownContent = fs.readFileSync(readmeMdPath, 'utf8');
// 添加基本的 markdown 样式
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>README</title>
<style>
body {
max-width: 800px;
margin: 0 auto;
padding: 20px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
line-height: 1.6;
}
pre {
background-color: #f6f8fa;
padding: 16px;
border-radius: 6px;
overflow: auto;
}
code {
background-color: #f6f8fa;
padding: 0.2em 0.4em;
border-radius: 3px;
}
img {
max-width: 100%;
}
table {
border-collapse: collapse;
width: 100%;
}
table td, table th {
border: 1px solid #dfe2e5;
padding: 6px 13px;
}
blockquote {
border-left: 4px solid #dfe2e5;
margin: 0;
padding: 0 1em;
color: #6a737d;
}
</style>
</head>
<body>
${md.render(markdownContent)}
</body>
</html>
`;
content = htmlContent;
}
switch (ext) {
case '.html':
minified = await minifyHtml(content, options);
@@ -68,12 +134,22 @@ async function main() {
const staticDir = path.join(__dirname, '..', 'static');
for (const file of files) {
const inputPath = path.join(staticDir, file);
const ext = path.extname(file);
const outputPath = path.join(
staticDir,
file.replace(ext, `.min${ext}`)
);
// 特殊处理 README.md 的输入路径
let inputPath;
let outputPath;
if (file.toLowerCase() === 'readme.md') {
inputPath = path.join(__dirname, '..', 'README.md');
outputPath = path.join(staticDir, 'readme.min.html');
} else {
inputPath = path.join(staticDir, file);
const ext = path.extname(file);
outputPath = path.join(
staticDir,
file.replace(ext, `.min${ext}`)
);
}
await minifyFile(inputPath, outputPath);
}
}

View File

@@ -10,6 +10,7 @@
"dependencies": {
"clean-css": "^5.3.3",
"html-minifier-terser": "^7.2.0",
"markdown-it": "^14.1.0",
"terser": "^5.37.0"
},
"engines": {
@@ -86,6 +87,12 @@
"node": ">=0.4.0"
}
},
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"license": "Python-2.0"
},
"node_modules/buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
@@ -166,6 +173,15 @@
"node": "^14.13.1 || >=16.0.0"
}
},
"node_modules/linkify-it": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz",
"integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==",
"license": "MIT",
"dependencies": {
"uc.micro": "^2.0.0"
}
},
"node_modules/lower-case": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz",
@@ -175,6 +191,29 @@
"tslib": "^2.0.3"
}
},
"node_modules/markdown-it": {
"version": "14.1.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz",
"integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==",
"license": "MIT",
"dependencies": {
"argparse": "^2.0.1",
"entities": "^4.4.0",
"linkify-it": "^5.0.0",
"mdurl": "^2.0.0",
"punycode.js": "^2.3.1",
"uc.micro": "^2.1.0"
},
"bin": {
"markdown-it": "bin/markdown-it.mjs"
}
},
"node_modules/mdurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz",
"integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==",
"license": "MIT"
},
"node_modules/no-case": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",
@@ -205,6 +244,15 @@
"tslib": "^2.0.3"
}
},
"node_modules/punycode.js": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
"integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/relateurl": {
"version": "0.2.7",
"resolved": "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz",
@@ -262,6 +310,12 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/uc.micro": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
"integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
"license": "MIT"
}
}
}

View File

@@ -8,6 +8,7 @@
"dependencies": {
"clean-css": "^5.3.3",
"html-minifier-terser": "^7.2.0",
"markdown-it": "^14.1.0",
"terser": "^5.37.0"
}
}