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( + '
\n ', + '
\n \n ' +); +c = c.replace( + ' \n\n \n\n
\n\n \n \n\n
f.endsWith('.html')); + +for (const f of files) { + const p = path.join(dir, f); + let c = fs.readFileSync(p, 'utf8'); + const before = c; + + // 1. theme.config.X. → theme.config.X?. (分组级安全导航,防止分组为 null 时 NPE) + c = c.replace(/theme\.config\.([a-z_]+)\./g, 'theme.config.$1?.'); + + // 2. nav_use_guide / nav_dev_guide 的 th:href 兜底,避免 @{null} + c = c.replace( + /\$\{theme\.config\.nav\?\.nav_use_guide\}/g, + "${theme.config.nav?.nav_use_guide ?: '/'}" + ); + c = c.replace( + /\$\{theme\.config\.nav\?\.nav_dev_guide\}/g, + "${theme.config.nav?.nav_dev_guide ?: '/'}" + ); + + if (c !== before) { + fs.writeFileSync(p, c); + console.log('✓', f); + } +} +console.log('done'); diff --git a/.rebuild.cjs b/.rebuild.cjs new file mode 100644 index 0000000..35c237d --- /dev/null +++ b/.rebuild.cjs @@ -0,0 +1,88 @@ +const fs = require('fs'); +const path = require('path'); + +const ROOT = process.cwd(); +const SKILL = '/Users/huanghui/.codebuddy/skills/halo-theme-dev/assets/theme-vite'; + +// 1. 创建目录 +for (const d of ['src', 'src/partials', 'src/css', 'src/js']) { + fs.mkdirSync(path.join(ROOT, d), { recursive: true }); +} + +// 2. 复制构建配置 +fs.copyFileSync(path.join(SKILL, 'package.json'), path.join(ROOT, 'package.json')); +fs.copyFileSync(path.join(SKILL, 'vite.config.ts'), path.join(ROOT, 'vite.config.ts')); +console.log('✓ 已复制 package.json / vite.config.ts'); + +// 3. 从 templates/index.html 提取 layout 骨架 +const idx = fs.readFileSync(path.join(ROOT, 'templates/index.html'), 'utf8'); +const header = idx.match(/