diff --git a/.beautify.cjs b/.beautify.cjs new file mode 100644 index 0000000..76c674c --- /dev/null +++ b/.beautify.cjs @@ -0,0 +1,36 @@ +const fs = require('fs'); +const path = require('path'); + +// 找到 assets 里的 css 文件 +const assets = fs.readdirSync('templates/assets'); +const cssFile = assets.find((f) => f.endsWith('.css') && f !== '.gitkeep'); +const css = fs.readFileSync(path.join('templates/assets', cssFile), 'utf8'); + +// 简单 CSS beautifier(带缩进) +function beautify(css) { + let out = ''; + let indent = 0; + let i = 0; + while (i < css.length) { + const ch = css[i]; + if (ch === '{') { + out += ' {\n'; + indent++; + } else if (ch === '}') { + indent = Math.max(0, indent - 1); + out += '\n' + ' '.repeat(indent) + '}\n'; + } else if (ch === ';') { + out += ';\n' + ' '.repeat(indent); + } else if (ch === '\n' || ch === '\r') { + // 跳过原始换行 + } else { + out += ch; + } + i++; + } + return out; +} + +const beautified = beautify(css); +fs.writeFileSync('src/css/main.css', beautified); +console.log('✓ CSS 反压缩完成 -> src/css/main.css (' + beautified.length + ' 字符)'); diff --git a/.fix-neq.cjs b/.fix-neq.cjs new file mode 100644 index 0000000..3124727 --- /dev/null +++ b/.fix-neq.cjs @@ -0,0 +1,21 @@ +const fs = require('fs'); +const files = [ + 'src/post.html', + 'src/index.html', + 'src/header-menu.html', + 'src/category.html', + 'src/user-menu.html' +]; +let total = 0; +for (const f of files) { + let c = fs.readFileSync(f, 'utf8'); + const before = c; + c = c.replace(/([\w.]+) != ([\w]+)/g, 'not ($1 == $2)'); + if (c !== before) { + fs.writeFileSync(f, c); + const diff = (before.match(/!=/g) || []).length; + console.log('✓', f, '替换', diff, '处'); + total += diff; + } +} +console.log('共替换', total, '处'); \ No newline at end of file diff --git a/.fix-null.cjs b/.fix-null.cjs new file mode 100644 index 0000000..1b3a3db --- /dev/null +++ b/.fix-null.cjs @@ -0,0 +1,18 @@ +const fs = require('fs'); +let c = fs.readFileSync('src/index.html', 'utf8'); + +// 1. modules 兜底为空列表 +c = c.replace( + '