全部 kit / 程式 kit

pagetext-kit

新站的寫法:畫面上給人看的字不寫在標籤裡,集中放每頁的內容檔。附自動檢查(違反就不給過)、給 AI 的規則、帶變數的字串小工具

版本 v0.1.0 · 更新 2026-11-19

範例

repo 裡的 example.js,整份照登。 在 GitHub 上看

'use strict';
// node example.js — makes a tiny site, checks it, fixes it, checks again.
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { fill, parts, check } = require('./index');

const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pagetext-example-'));
const write = (name, content) => {
  fs.mkdirSync(path.dirname(path.join(root, name)), { recursive: true });
  fs.writeFileSync(path.join(root, name), content);
};
const show = (line) => process.stdout.write(`${line}\n`);

write('app/page.tsx', 'export default function Page() {\n  return <h1 className="text-4xl">一個價錢,全部功能</h1>;\n}\n');
show('字寫在標籤裡:');
for (const p of check(root).problems) show(`  ${p.file}:${p.line}  「${p.text}」  ${p.why}`);

write('app/page.text.ts', "export const text = { title: '一個價錢,全部功能', count: '共 {count} 個方案' } as const;\n");
write('app/page.tsx', "import { text as t } from './page.text';\nexport default function Page() {\n  return <h1 className=\"text-4xl\">{t.title}</h1>;\n}\n");
show(`搬到內容檔之後:${check(root).problems.length} 處`);

show(fill('共 {count} 個方案', { count: 2 }));
show(JSON.stringify(parts('同意 {terms} 後繼續', { terms: '條款' })));
fs.rmSync(root, { recursive: true, force: true });

↑↓ 選擇 Enter 前往 Esc 關閉