- 移除了公告功能,替换为固定公告内容 - 更新了站点信息,包括友情链接和邮箱地址 - 优化了图片总数和接口文档的展示方式 - 重新实现了构建 ID 生成逻辑,使用项目文件哈希值代替时间戳
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import crypto from 'crypto';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
const generateProjectHash = () => {
|
|
const hash = crypto.createHash('sha256');
|
|
const walk = (dir) => {
|
|
const files = fs.readdirSync(dir);
|
|
files.forEach(file => {
|
|
const filePath = path.join(dir, file);
|
|
const stat = fs.statSync(filePath);
|
|
if (stat.isDirectory()) {
|
|
walk(filePath);
|
|
} else {
|
|
hash.update(fs.readFileSync(filePath));
|
|
}
|
|
});
|
|
};
|
|
|
|
walk(path.join(__dirname, '..'));
|
|
return hash.digest('hex').substring(0, 7); // 使用前10个字符作为短哈希
|
|
};
|
|
|
|
const generateBuildId = () => {
|
|
const projectHash = generateProjectHash();
|
|
const envFilePath = path.join(__dirname, '..', '.env.local');
|
|
|
|
if (fs.existsSync(envFilePath)) {
|
|
fs.unlinkSync(envFilePath);
|
|
}
|
|
|
|
fs.writeFileSync(envFilePath, `NEXT_PUBLIC_BUILD_ID=${projectHash}`);
|
|
console.log(`Build ID generated: ${projectHash}`);
|
|
};
|
|
|
|
generateBuildId(); |