create-claudecraft 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -178
- package/bin/cli.js +186 -1
- package/dist/answers.d.ts +269 -0
- package/dist/answers.js +215 -0
- package/dist/ink-prompts.d.ts +90 -12
- package/dist/ink-prompts.js +371 -330
- package/dist/lettering.d.ts +2 -0
- package/dist/lettering.js +28 -0
- package/lib/apps.mjs +141 -0
- package/lib/github.mjs +24 -0
- package/lib/init.mjs +153 -0
- package/lib/ports.mjs +56 -0
- package/lib/scaffold.mjs +218 -0
- package/lib/upgrade.mjs +164 -0
- package/package.json +39 -33
- package/templates/astro/.editorconfig +15 -0
- package/templates/astro/.env.example +2 -0
- package/templates/astro/.github/workflows/ci.yml +37 -0
- package/templates/astro/.github/workflows/deploy.yml +46 -0
- package/templates/astro/.nvmrc +1 -0
- package/templates/astro/.prettierignore +10 -0
- package/templates/astro/.prettierrc.json +7 -0
- package/templates/astro/.vscode/extensions.json +3 -0
- package/templates/astro/.vscode/settings.json +12 -0
- package/templates/astro/AGENTS.md +100 -0
- package/templates/astro/README.md +42 -0
- package/templates/astro/_CLAUDE.md +1 -0
- package/templates/astro/_claude/launch.json +13 -0
- package/templates/astro/_claude/settings.json +22 -0
- package/templates/astro/_codex/environments/environment.toml +20 -0
- package/templates/astro/_gitignore +31 -0
- package/templates/astro/_npmrc +8 -0
- package/templates/astro/_super.engineering/config.json +8 -0
- package/templates/astro/_zed/tasks.json +5 -0
- package/templates/astro/astro.config.mjs +111 -0
- package/templates/astro/docs/README.md +7 -0
- package/templates/astro/docs/decisions.md +3 -0
- package/templates/astro/docs/inbox.md +7 -0
- package/templates/astro/docs/kit/agent-apps.md +15 -0
- package/templates/astro/docs/kit/analytics.md +13 -0
- package/templates/astro/docs/kit/deploy.md +9 -0
- package/templates/astro/docs/kit/images.md +10 -0
- package/templates/astro/docs/kit/languages.md +8 -0
- package/templates/astro/docs/kit/local.md +16 -0
- package/templates/astro/docs/kit/seo.md +15 -0
- package/templates/astro/docs/kit/structure.md +40 -0
- package/templates/astro/docs/kit/upgrade.md +19 -0
- package/templates/astro/functions/_middleware.js +25 -0
- package/templates/astro/intent.md +40 -0
- package/templates/astro/package.json +46 -0
- package/templates/astro/public/_headers +17 -0
- package/templates/astro/public/_routes.json +5 -0
- package/templates/astro/public/apple-touch-icon.png +0 -0
- package/templates/astro/public/favicon-16.png +0 -0
- package/templates/astro/public/favicon-32.png +0 -0
- package/templates/astro/public/favicon.ico +0 -0
- package/templates/astro/public/favicon.svg +4 -0
- package/templates/astro/public/icon-192.png +0 -0
- package/templates/astro/public/icon-512.png +0 -0
- package/templates/astro/public/og-image.png +0 -0
- package/templates/astro/scripts/chrome.mjs +138 -0
- package/templates/astro/scripts/deploy.sh +69 -0
- package/templates/astro/scripts/generate-icons.mjs +73 -0
- package/templates/astro/scripts/generate-og.mjs +66 -0
- package/templates/astro/scripts/lint-copy.mjs +67 -0
- package/templates/astro/scripts/local-domain.mjs +115 -0
- package/templates/astro/scripts/markdown-pages.mjs +142 -0
- package/templates/astro/scripts/og-template.html +73 -0
- package/templates/astro/scripts/shared.mjs +33 -0
- package/templates/astro/scripts/verify-build.mjs +283 -0
- package/templates/astro/scripts/verify.mjs +19 -0
- package/templates/astro/site.config.mjs +85 -0
- package/templates/astro/src/components/Analytics.astro +49 -0
- package/templates/astro/src/components/Consent.astro +52 -0
- package/templates/astro/src/components/Counter.tsx +20 -0
- package/templates/astro/src/data/README.md +18 -0
- package/templates/astro/src/dev/styleguide.astro +43 -0
- package/templates/astro/src/env.d.ts +1 -0
- package/templates/astro/src/i18n/ar.json +29 -0
- package/templates/astro/src/i18n/de.json +29 -0
- package/templates/astro/src/i18n/en.json +29 -0
- package/templates/astro/src/i18n/es.json +29 -0
- package/templates/astro/src/i18n/fr.json +29 -0
- package/templates/astro/src/i18n/he.json +29 -0
- package/templates/astro/src/i18n/hi.json +29 -0
- package/templates/astro/src/i18n/index.ts +80 -0
- package/templates/astro/src/i18n/it.json +29 -0
- package/templates/astro/src/i18n/ja.json +29 -0
- package/templates/astro/src/i18n/ko.json +29 -0
- package/templates/astro/src/i18n/nl.json +29 -0
- package/templates/astro/src/i18n/pl.json +29 -0
- package/templates/astro/src/i18n/pt-br.json +29 -0
- package/templates/astro/src/i18n/ro.json +29 -0
- package/templates/astro/src/i18n/ru.json +29 -0
- package/templates/astro/src/i18n/sv.json +29 -0
- package/templates/astro/src/i18n/tr.json +29 -0
- package/templates/astro/src/i18n/uk.json +29 -0
- package/templates/astro/src/i18n/zh-cn.json +29 -0
- package/templates/astro/src/layouts/BaseLayout.astro +205 -0
- package/templates/astro/src/lib/cn.ts +7 -0
- package/templates/astro/src/lib/consent.ts +32 -0
- package/templates/astro/src/lib/seo.ts +18 -0
- package/templates/astro/src/lib/theme.ts +5 -0
- package/templates/astro/src/pages/404.astro +7 -0
- package/templates/astro/src/pages/[...locale]/404.astro +25 -0
- package/templates/astro/src/pages/[...locale]/about.astro +25 -0
- package/templates/astro/src/pages/[...locale]/index.astro +30 -0
- package/templates/astro/src/pages/[...locale]/privacy.astro +28 -0
- package/templates/astro/src/pages/robots.txt.ts +16 -0
- package/templates/astro/src/pages/site.webmanifest.ts +26 -0
- package/templates/astro/src/styles/global.css +163 -0
- package/templates/astro/t3.json +22 -0
- package/templates/astro/tsconfig.json +13 -0
- package/templates/astro/wrangler.toml +8 -0
- package/templates/react/.editorconfig +15 -0
- package/templates/react/.env.example +2 -0
- package/templates/react/.nvmrc +1 -0
- package/templates/react/.prettierignore +11 -0
- package/templates/react/.prettierrc.json +5 -0
- package/templates/react/.vscode/extensions.json +3 -0
- package/templates/react/.vscode/settings.json +4 -0
- package/templates/react/AGENTS.md +64 -0
- package/templates/react/README.md +31 -0
- package/templates/react/_CLAUDE.md +1 -0
- package/templates/react/_claude/launch.json +13 -0
- package/templates/react/_claude/settings.json +21 -0
- package/templates/react/_codex/environments/environment.toml +20 -0
- package/templates/react/_gitignore +17 -0
- package/templates/react/_npmrc +8 -0
- package/templates/react/_super.engineering/config.json +8 -0
- package/templates/react/_zed/tasks.json +5 -0
- package/templates/react/docs/decisions.md +3 -0
- package/templates/react/docs/inbox.md +7 -0
- package/templates/react/index.html +14 -0
- package/templates/react/package.json +47 -0
- package/templates/react/public/favicon.svg +5 -0
- package/templates/react/scripts/lint-copy.mjs +46 -0
- package/templates/react/scripts/lint-tokens.mjs +44 -0
- package/templates/react/scripts/local-domain.mjs +115 -0
- package/templates/react/scripts/verify.mjs +20 -0
- package/templates/react/site.config.mjs +23 -0
- package/templates/react/src/App.test.tsx +15 -0
- package/templates/react/src/App.tsx +21 -0
- package/templates/react/src/components/ErrorBoundary.tsx +42 -0
- package/templates/react/src/components/SkipLink.tsx +10 -0
- package/templates/react/src/config/site.ts +5 -0
- package/templates/react/src/lib/cn.ts +7 -0
- package/templates/react/src/main.tsx +13 -0
- package/templates/react/src/pages/HomePage.tsx +71 -0
- package/templates/react/src/pages/NotFoundPage.tsx +21 -0
- package/templates/react/src/styles/global.css +96 -0
- package/templates/react/src/test-setup.ts +1 -0
- package/templates/react/t3.json +22 -0
- package/templates/{base → react}/tsconfig.json +3 -3
- package/templates/react/vite.config.ts +26 -0
- package/templates/shared/_claude/hooks/design-lint.mjs +67 -0
- package/templates/shared/_claude/skills/design-quality/SKILL.md +113 -0
- package/templates/shared/_claude/skills/design-quality/references/composition-palette.md +87 -0
- package/templates/shared/_claude/skills/design-quality/references/copy-tells.md +49 -0
- package/templates/shared/_claude/skills/design-quality/references/visual-critic.md +75 -0
- package/templates/shared/design.md +148 -0
- package/templates/shared/intent.md +28 -0
- package/dist/constants.d.ts +0 -71
- package/dist/constants.js +0 -128
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -229
- package/dist/prompts.d.ts +0 -16
- package/dist/prompts.js +0 -434
- package/dist/scaffold.d.ts +0 -19
- package/dist/scaffold.js +0 -303
- package/dist/ui.d.ts +0 -27
- package/dist/ui.js +0 -254
- package/templates/app/App.tsx +0 -21
- package/templates/base/CLAUDE.md +0 -332
- package/templates/base/eslint.config.js +0 -28
- package/templates/base/index.html +0 -17
- package/templates/base/package.json +0 -43
- package/templates/base/postcss.config.js +0 -6
- package/templates/base/tailwind.config.js +0 -81
- package/templates/base/vite.config.ts +0 -16
- package/templates/commands/brainstorm.md +0 -6
- package/templates/commands/build.md +0 -41
- package/templates/commands/execute-plan.md +0 -6
- package/templates/commands/lint.md +0 -41
- package/templates/commands/ralph.md +0 -113
- package/templates/commands/typecheck.md +0 -44
- package/templates/commands/write-plan.md +0 -6
- package/templates/components/ErrorBoundary.tsx +0 -49
- package/templates/components/ui/Button.tsx +0 -60
- package/templates/components/ui/CodeBlock.tsx +0 -46
- package/templates/components/ui/CopyCommand.tsx +0 -38
- package/templates/components/ui/FilePreview.tsx +0 -46
- package/templates/components/ui/SkipLink.tsx +0 -7
- package/templates/components/ui/ThemeSelector.tsx +0 -41
- package/templates/components/ui/UICarousel.tsx +0 -309
- package/templates/context/ThemeContext.tsx +0 -61
- package/templates/homepage/HomePage.tsx +0 -534
- package/templates/homepage/NotFoundPage.tsx +0 -17
- package/templates/hooks/README.md +0 -82
- package/templates/hooks/check-branch.js +0 -27
- package/templates/hooks/typecheck-after-edit.js +0 -51
- package/templates/index.css +0 -67
- package/templates/lib/utils.ts +0 -9
- package/templates/main.tsx +0 -16
- package/templates/settings/MCP_SETUP.md +0 -76
- package/templates/settings/settings.json +0 -16
- package/templates/settings/settings.local.json +0 -37
- package/templates/skills/design/a11y-audit/SKILL.md +0 -173
- package/templates/skills/design/design-polish/SKILL.md +0 -75
- package/templates/skills/design/figma-to-code/SKILL.md +0 -157
- package/templates/skills/design/json-ld/SKILL.md +0 -125
- package/templates/skills/design/microcopy/SKILL.md +0 -197
- package/templates/skills/design/og-image/SKILL.md +0 -157
- package/templates/skills/design/ralph-wiggum-loops/SKILL.md +0 -299
- package/templates/skills/design/react-best-practices/SKILL.md +0 -106
- package/templates/skills/design/react-best-practices/references/react-performance-guidelines.md +0 -143
- package/templates/skills/design/seo-review/SKILL.md +0 -96
- package/templates/skills/design/sitemap-generator/SKILL.md +0 -66
- package/templates/skills/design/testing-patterns/SKILL.md +0 -276
- package/templates/skills/design/ui-skills/SKILL.md +0 -85
- package/templates/skills/design/visual-iteration/SKILL.md +0 -88
- package/templates/skills/workflow/brainstorming/SKILL.md +0 -54
- package/templates/skills/workflow/dispatching-parallel-agents/SKILL.md +0 -180
- package/templates/skills/workflow/executing-plans/SKILL.md +0 -76
- package/templates/skills/workflow/finishing-a-development-branch/SKILL.md +0 -200
- package/templates/skills/workflow/receiving-code-review/SKILL.md +0 -213
- package/templates/skills/workflow/requesting-code-review/SKILL.md +0 -105
- package/templates/skills/workflow/requesting-code-review/code-reviewer.md +0 -146
- package/templates/skills/workflow/subagent-driven-development/SKILL.md +0 -240
- package/templates/skills/workflow/subagent-driven-development/code-quality-reviewer-prompt.md +0 -20
- package/templates/skills/workflow/subagent-driven-development/implementer-prompt.md +0 -78
- package/templates/skills/workflow/subagent-driven-development/spec-reviewer-prompt.md +0 -61
- package/templates/skills/workflow/systematic-debugging/CREATION-LOG.md +0 -119
- package/templates/skills/workflow/systematic-debugging/SKILL.md +0 -296
- package/templates/skills/workflow/systematic-debugging/condition-based-waiting-example.ts +0 -158
- package/templates/skills/workflow/systematic-debugging/condition-based-waiting.md +0 -115
- package/templates/skills/workflow/systematic-debugging/defense-in-depth.md +0 -122
- package/templates/skills/workflow/systematic-debugging/find-polluter.sh +0 -63
- package/templates/skills/workflow/systematic-debugging/root-cause-tracing.md +0 -169
- package/templates/skills/workflow/systematic-debugging/test-academic.md +0 -14
- package/templates/skills/workflow/systematic-debugging/test-pressure-1.md +0 -58
- package/templates/skills/workflow/systematic-debugging/test-pressure-2.md +0 -68
- package/templates/skills/workflow/systematic-debugging/test-pressure-3.md +0 -69
- package/templates/skills/workflow/test-driven-development/SKILL.md +0 -371
- package/templates/skills/workflow/test-driven-development/testing-anti-patterns.md +0 -299
- package/templates/skills/workflow/using-git-worktrees/SKILL.md +0 -217
- package/templates/skills/workflow/using-superpowers/SKILL.md +0 -87
- package/templates/skills/workflow/verification-before-completion/SKILL.md +0 -139
- package/templates/skills/workflow/writing-plans/SKILL.md +0 -116
- package/templates/skills/workflow/writing-skills/SKILL.md +0 -655
- package/templates/skills/workflow/writing-skills/anthropic-best-practices.md +0 -1150
- package/templates/skills/workflow/writing-skills/examples/CLAUDE_MD_TESTING.md +0 -189
- package/templates/skills/workflow/writing-skills/graphviz-conventions.dot +0 -172
- package/templates/skills/workflow/writing-skills/persuasion-principles.md +0 -187
- package/templates/skills/workflow/writing-skills/render-graphs.js +0 -168
- package/templates/skills/workflow/writing-skills/testing-skills-with-subagents.md +0 -384
- package/templates/types/index.ts +0 -17
- /package/templates/{vite-env.d.ts → react/src/vite-env.d.ts} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Build and upload dist/ to Cloudflare Pages (Direct Upload, static, no SSR adapter).
|
|
3
|
+
# Needs `npx wrangler@4.158.0 login` once, or CLOUDFLARE_API_TOKEN with Pages: Edit plus CLOUDFLARE_ACCOUNT_ID.
|
|
4
|
+
# Refuses a localhost SITE_URL, a build that still has the placeholder sentence, and one with
|
|
5
|
+
# analytics on and the privacy text unwritten. Creates the Pages project on first deploy (name
|
|
6
|
+
# from wrangler.toml, or CLOUDFLARE_PAGES_PROJECT). .github/workflows/deploy.yml runs this on
|
|
7
|
+
# every push to main once the repository has its Cloudflare secrets.
|
|
8
|
+
#
|
|
9
|
+
# npm run deploy -- https://example.com # SITE_URL for this build, branch main
|
|
10
|
+
# npm run deploy -- https://example.com preview # any other branch is a preview deploy
|
|
11
|
+
# CLOUDFLARE_PAGES_PROJECT=my-pages npm run deploy
|
|
12
|
+
#
|
|
13
|
+
# pages.dev hosts are noindexed unless the canonical is the pages.dev host.
|
|
14
|
+
set -euo pipefail
|
|
15
|
+
|
|
16
|
+
WRANGLER=wrangler@4.158.0
|
|
17
|
+
PLACEHOLDER='fill the one-sentence intent'
|
|
18
|
+
PRIVACY_PLACEHOLDER='Privacy text to write'
|
|
19
|
+
|
|
20
|
+
cd "$(dirname "$0")/.."
|
|
21
|
+
|
|
22
|
+
if [[ -n "${1:-}" ]]; then export SITE_URL="$1"; fi
|
|
23
|
+
BRANCH="${2:-main}"
|
|
24
|
+
PROJECT="${CLOUDFLARE_PAGES_PROJECT:-$(sed -n 's/^name *= *"\([^"]*\)".*/\1/p' wrangler.toml | head -1)}"
|
|
25
|
+
|
|
26
|
+
HOST="$(node --input-type=module -e "
|
|
27
|
+
import('./site.config.mjs').then(
|
|
28
|
+
(m) => console.log(new URL(m.siteUrl).hostname),
|
|
29
|
+
(e) => { console.error(e.message); process.exit(1); },
|
|
30
|
+
);")"
|
|
31
|
+
case "$HOST" in
|
|
32
|
+
localhost | *.localhost | 127.* | 0.0.0.0)
|
|
33
|
+
echo "SITE_URL is $HOST. Pass the real origin: npm run deploy -- https://your-domain"
|
|
34
|
+
exit 1
|
|
35
|
+
;;
|
|
36
|
+
esac
|
|
37
|
+
|
|
38
|
+
# Listing the projects is the login check: a token limited to Pages can do it, and `whoami` refuses that token.
|
|
39
|
+
if ! PROJECTS="$(npx --yes "$WRANGLER" pages project list --json 2>/dev/null)"; then
|
|
40
|
+
echo "Not logged in to Cloudflare. Run: npx $WRANGLER login (or set CLOUDFLARE_API_TOKEN with Pages: Edit, and CLOUDFLARE_ACCOUNT_ID)"
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
npm run build
|
|
45
|
+
|
|
46
|
+
if grep -rqsF "$PLACEHOLDER" dist; then
|
|
47
|
+
echo "dist/ still has the placeholder intent. Find it with: grep -rlF '$PLACEHOLDER' src public"
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
if grep -rqsF "$PRIVACY_PLACEHOLDER" dist; then
|
|
52
|
+
echo "Analytics are on and /privacy/ is unwritten. Write privacyBody in every src/i18n/<code>.json."
|
|
53
|
+
exit 1
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
printf '\nhttps://:version.:project.pages.dev/*\n X-Robots-Tag: noindex\n'
|
|
58
|
+
if [[ "$HOST" != *.pages.dev ]]; then printf 'https://:project.pages.dev/*\n X-Robots-Tag: noindex\n'; fi
|
|
59
|
+
} >>dist/_headers
|
|
60
|
+
|
|
61
|
+
# --force keeps a new project on Pages when an agent runs this (wrangler would create a Worker).
|
|
62
|
+
if ! PROJECT="$PROJECT" node -e '
|
|
63
|
+
const list = JSON.parse(require("node:fs").readFileSync(0, "utf8"));
|
|
64
|
+
process.exit(list.some((p) => p["Project Name"] === process.env.PROJECT) ? 0 : 1);
|
|
65
|
+
' <<<"$PROJECTS"; then
|
|
66
|
+
npx --yes "$WRANGLER" pages project create "$PROJECT" --production-branch=main --force
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
npx --yes "$WRANGLER" pages deploy dist --project-name="$PROJECT" --branch="$BRANCH" --commit-dirty=true
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Render public/favicon.svg on the site's paper color at each size: favicon-16/32.png,
|
|
4
|
+
* apple-touch-icon.png (180), icon-192/512.png and favicon.ico (16/32/48).
|
|
5
|
+
* Needs Google Chrome or Chromium (scripts/chrome.mjs).
|
|
6
|
+
*
|
|
7
|
+
* npm run generate:icons
|
|
8
|
+
*/
|
|
9
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
13
|
+
import { launchChrome } from './chrome.mjs';
|
|
14
|
+
import { cssColor } from './shared.mjs';
|
|
15
|
+
|
|
16
|
+
const pub = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'public');
|
|
17
|
+
const PNGS = [
|
|
18
|
+
[16, 'favicon-16.png'],
|
|
19
|
+
[32, 'favicon-32.png'],
|
|
20
|
+
[180, 'apple-touch-icon.png'],
|
|
21
|
+
[192, 'icon-192.png'],
|
|
22
|
+
[512, 'icon-512.png'],
|
|
23
|
+
];
|
|
24
|
+
const ICO = [16, 32, 48];
|
|
25
|
+
const fail = (message) => {
|
|
26
|
+
console.error(`generate-icons: ${message}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** An .ico file holding one PNG per size. */
|
|
31
|
+
function ico(images) {
|
|
32
|
+
const header = Buffer.alloc(6 + 16 * images.length);
|
|
33
|
+
header.writeUInt16LE(1, 2); // type: icon
|
|
34
|
+
header.writeUInt16LE(images.length, 4);
|
|
35
|
+
let offset = header.length;
|
|
36
|
+
images.forEach(({ size, png }, i) => {
|
|
37
|
+
const entry = 6 + 16 * i;
|
|
38
|
+
header.writeUInt8(size, entry);
|
|
39
|
+
header.writeUInt8(size, entry + 1);
|
|
40
|
+
header.writeUInt16LE(1, entry + 4); // color planes
|
|
41
|
+
header.writeUInt16LE(32, entry + 6); // bits per pixel
|
|
42
|
+
header.writeUInt32LE(png.length, entry + 8);
|
|
43
|
+
header.writeUInt32LE(offset, entry + 12);
|
|
44
|
+
offset += png.length;
|
|
45
|
+
});
|
|
46
|
+
return Buffer.concat([header, ...images.map(({ png }) => png)]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const paper = cssColor('paper') ?? fail('--color-paper not found in src/styles/global.css.');
|
|
50
|
+
const chrome = (await launchChrome()) ?? fail('install Google Chrome or Chromium and retry.');
|
|
51
|
+
const tmp = mkdtempSync(path.join(tmpdir(), 'icons-'));
|
|
52
|
+
try {
|
|
53
|
+
const page = path.join(tmp, 'icon.html');
|
|
54
|
+
writeFileSync(
|
|
55
|
+
page,
|
|
56
|
+
`<!doctype html><style>html,body{margin:0;width:100vw;height:100vh;overflow:hidden;background:${paper}}img{display:block;width:100%;height:100%}</style><img src="${pathToFileURL(path.join(pub, 'favicon.svg'))}" alt="" />`,
|
|
57
|
+
);
|
|
58
|
+
const render = async (size) => {
|
|
59
|
+
const tab = await chrome.tab(size, size);
|
|
60
|
+
await tab.goto(pathToFileURL(page).href);
|
|
61
|
+
const png = await tab.screenshot({ format: 'png' });
|
|
62
|
+
await tab.close();
|
|
63
|
+
return png;
|
|
64
|
+
};
|
|
65
|
+
for (const [size, name] of PNGS) writeFileSync(path.join(pub, name), await render(size));
|
|
66
|
+
const images = [];
|
|
67
|
+
for (const size of ICO) images.push({ size, png: await render(size) });
|
|
68
|
+
writeFileSync(path.join(pub, 'favicon.ico'), ico(images));
|
|
69
|
+
} finally {
|
|
70
|
+
await chrome.close();
|
|
71
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
72
|
+
}
|
|
73
|
+
console.log(`generate-icons: ${[...PNGS.map(([, name]) => name), 'favicon.ico'].join(', ')}`);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Render public/og-image.png (1200×630) from scripts/og-template.html with this site's name,
|
|
4
|
+
* default-locale description, lang/dir, and paper/ink/accent from src/styles/global.css.
|
|
5
|
+
* Needs Google Chrome or Chromium (scripts/chrome.mjs).
|
|
6
|
+
*
|
|
7
|
+
* npm run generate:og
|
|
8
|
+
*/
|
|
9
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
13
|
+
import { defaultLocale, siteName } from '../site.config.mjs';
|
|
14
|
+
import { launchChrome } from './chrome.mjs';
|
|
15
|
+
import { catalog, cssColor } from './shared.mjs';
|
|
16
|
+
|
|
17
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
18
|
+
const read = (file) => readFileSync(path.join(root, file), 'utf8');
|
|
19
|
+
const fail = (message) => {
|
|
20
|
+
console.error(`generate-og: ${message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const { meta, description } = catalog(defaultLocale);
|
|
25
|
+
if (description.includes('fill the one-sentence intent')) {
|
|
26
|
+
fail(`write the one-sentence description in src/i18n/${defaultLocale}.json first.`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const color = (name) => cssColor(name) ?? fail(`--color-${name} not found in src/styles/global.css.`);
|
|
30
|
+
|
|
31
|
+
const escape = (text) =>
|
|
32
|
+
String(text).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
33
|
+
|
|
34
|
+
function fill(html, slot, text) {
|
|
35
|
+
const element = new RegExp(`(<(\\w+)[^>]*data-slot="${slot}"[^>]*>)[\\s\\S]*?(</\\2>)`);
|
|
36
|
+
if (!element.test(html)) fail(`data-slot="${slot}" not found in scripts/og-template.html.`);
|
|
37
|
+
return html.replace(element, (_, open, _tag, close) => open + escape(text) + close);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let html = read('scripts/og-template.html')
|
|
41
|
+
.replace(
|
|
42
|
+
/<html[^>]*>/,
|
|
43
|
+
() => `<html lang="${escape(meta.hreflang)}" dir="${escape(meta.dir)}" data-font="${escape(meta.font)}">`,
|
|
44
|
+
)
|
|
45
|
+
.replace('<head>', () => `<head>\n <base href="${pathToFileURL(path.join(root, 'scripts'))}/" />`)
|
|
46
|
+
.replace(
|
|
47
|
+
'</style>',
|
|
48
|
+
() =>
|
|
49
|
+
` :root { --paper: ${color('paper')}; --ink: ${color('ink')}; --accent: ${color('accent')}; }\n </style>`,
|
|
50
|
+
);
|
|
51
|
+
html = fill(fill(html, 'name', siteName), 'description', description);
|
|
52
|
+
|
|
53
|
+
const chrome = (await launchChrome()) ?? fail('install Google Chrome or Chromium and retry.');
|
|
54
|
+
const tmp = mkdtempSync(path.join(tmpdir(), 'og-'));
|
|
55
|
+
try {
|
|
56
|
+
const page = path.join(tmp, 'og.html');
|
|
57
|
+
writeFileSync(page, html);
|
|
58
|
+
const tab = await chrome.tab(1200, 630);
|
|
59
|
+
await tab.goto(pathToFileURL(page).href);
|
|
60
|
+
await tab.evaluate('document.fonts.ready.then(() => true)');
|
|
61
|
+
writeFileSync(path.join(root, 'public', 'og-image.png'), await tab.screenshot({ format: 'png' }));
|
|
62
|
+
} finally {
|
|
63
|
+
await chrome.close();
|
|
64
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
65
|
+
}
|
|
66
|
+
console.log(`generate-og: public/og-image.png (${siteName}, ${defaultLocale})`);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// House voice lint on what a reader or agent actually gets: per-page markdown,
|
|
2
|
+
// llms.txt / llms-full.txt and every string in src/i18n. Runs after markdown-pages
|
|
3
|
+
// on `npm run build`.
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { defaultLocale, locales } from '../site.config.mjs';
|
|
8
|
+
import { catalog, dist, distFiles } from './shared.mjs';
|
|
9
|
+
|
|
10
|
+
const RULES = [
|
|
11
|
+
[
|
|
12
|
+
/\b(leverag\w*|disrupt\w*|ai-powered|game-chang\w*|unlock\w*|supercharg\w*|10x|scale yourself|seamless\w*|empower\w*|cutting-edge|best-in-class|synerg\w*)\b/i,
|
|
13
|
+
'SaaS speak',
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
/\b(passive income|while you sleep|financial freedom|side hustle|make money|easy money|get rich)\b/i,
|
|
17
|
+
'hustle or passive-income tone',
|
|
18
|
+
],
|
|
19
|
+
[/—/, 'an em dash (use a period, comma, colon, or parentheses)'],
|
|
20
|
+
[/!(?!\[)/, 'an exclamation mark'],
|
|
21
|
+
[/\b(lorem|ipsum|TODO|TBD)\b/, 'placeholder text'],
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const problems = [];
|
|
25
|
+
|
|
26
|
+
const check = (name, text) => {
|
|
27
|
+
const body = text.replace(/^---\n[\s\S]*?\n---\n/, '');
|
|
28
|
+
body.split('\n').forEach((line, i) => {
|
|
29
|
+
let clean = line
|
|
30
|
+
.replace(/`[^`]*`/g, '')
|
|
31
|
+
.replace(/\]\([^)]*\)/g, ']')
|
|
32
|
+
.replace(/https?:\/\/\S+/g, '')
|
|
33
|
+
.replace(/\{\{[^}]+\}\}/g, '');
|
|
34
|
+
for (const [re, why] of RULES) {
|
|
35
|
+
if (re.test(clean)) problems.push(`${name}:${i + 1}: ${why}: ${line.trim().slice(0, 120)}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
for (const rel of [...(await distFiles('index.md')), 'llms.txt', 'llms-full.txt']) {
|
|
41
|
+
if (existsSync(join(dist, rel))) check(rel, await readFile(join(dist, rel), 'utf8'));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Catalog strings, flattened to description + ui.<key>.
|
|
45
|
+
const strings = (code) => {
|
|
46
|
+
const { description, ui } = catalog(code);
|
|
47
|
+
return { description, ...Object.fromEntries(Object.entries(ui).map(([key, text]) => [`ui.${key}`, text])) };
|
|
48
|
+
};
|
|
49
|
+
const base = strings(defaultLocale);
|
|
50
|
+
const untranslated = [];
|
|
51
|
+
for (const code of locales) {
|
|
52
|
+
const own = strings(code);
|
|
53
|
+
for (const [key, text] of Object.entries(own)) check(`src/i18n/${code}.json ${key}`, text);
|
|
54
|
+
const same = code === defaultLocale ? [] : Object.keys(base).filter((key) => own[key] === base[key]);
|
|
55
|
+
if (same.length) untranslated.push(`${code}.json: ${same.join(', ')}`);
|
|
56
|
+
}
|
|
57
|
+
if (untranslated.length) {
|
|
58
|
+
console.warn(
|
|
59
|
+
`lint-copy: same text as ${defaultLocale}.json (untranslated?)\n ${untranslated.join('\n ')}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (problems.length) {
|
|
64
|
+
console.error(`lint-copy: ${problems.length} problem(s)\n${problems.join('\n')}`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
console.log('lint-copy: ok');
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// npm run domain: serve this site at https://<name>.localhost/ through the Homebrew Caddy.
|
|
2
|
+
// It writes one file, <brew prefix>/etc/caddy.d/<name>.caddy, then validates and reloads Caddy.
|
|
3
|
+
// Without a running brew Caddy it changes nothing. `npm run domain -- --remove` undoes it.
|
|
4
|
+
// A <name>.caddy that claudecraft did not write is never replaced or removed.
|
|
5
|
+
// The last line it prints is always the URL that works.
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { devPort } from '../site.config.mjs';
|
|
11
|
+
|
|
12
|
+
const { name } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
13
|
+
const pretty = `https://${name}.localhost/`;
|
|
14
|
+
const fallback = `http://${name}.localhost:${devPort}/`;
|
|
15
|
+
// Tests point CLAUDECRAFT_CADDY_DIR at a temp folder: the file is written there and no Caddy is touched.
|
|
16
|
+
const testDir = process.env.CLAUDECRAFT_CADDY_DIR;
|
|
17
|
+
// Any claudecraft site's first line, so a moved or recreated site can still replace its own file.
|
|
18
|
+
const GENERATED = /^# Generated by .+\/scripts\/local-domain\.mjs — do not edit by hand\.$/;
|
|
19
|
+
|
|
20
|
+
/** True when the file is missing or a claudecraft site wrote it. */
|
|
21
|
+
const ours = (/** @type {string} */ file) =>
|
|
22
|
+
!existsSync(file) || GENERATED.test(readFileSync(file, 'utf8').split('\n', 1)[0]);
|
|
23
|
+
|
|
24
|
+
/** stdout of a command, or '' when it is missing or fails. */
|
|
25
|
+
const output = (/** @type {string} */ command, /** @type {string[]} */ args) => {
|
|
26
|
+
const result = spawnSync(command, args, { encoding: 'utf8' });
|
|
27
|
+
return result.status === 0 ? result.stdout.trim() : '';
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const { url, note = '', error = '' } = await run(process.argv.includes('--remove'));
|
|
31
|
+
if (note) console.log(note);
|
|
32
|
+
if (error) {
|
|
33
|
+
console.error(error);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
}
|
|
36
|
+
console.log(url);
|
|
37
|
+
|
|
38
|
+
/** @param {boolean} remove */
|
|
39
|
+
async function run(remove) {
|
|
40
|
+
// node --test sets NODE_TEST_CONTEXT. A test that forgot the seam must never reach the real Caddy.
|
|
41
|
+
if (!testDir && process.env.NODE_TEST_CONTEXT) {
|
|
42
|
+
return { url: fallback, error: 'Tests must set CLAUDECRAFT_CADDY_DIR. The real Caddy was not touched.' };
|
|
43
|
+
}
|
|
44
|
+
const prefix = testDir ? '' : output('brew', ['--prefix']);
|
|
45
|
+
if (!testDir && !(prefix && output('caddy', ['version']))) {
|
|
46
|
+
const setup = 'brew install caddy && brew services start caddy && caddy trust';
|
|
47
|
+
return { url: fallback, note: remove ? '' : `Caddy is not installed. For ${pretty}: ${setup}` };
|
|
48
|
+
}
|
|
49
|
+
const caddyDir = testDir || path.join(prefix, 'etc', 'caddy.d');
|
|
50
|
+
const caddyfile = path.join(prefix, 'etc', 'Caddyfile');
|
|
51
|
+
const site = path.join(caddyDir, `${name}.caddy`);
|
|
52
|
+
// Other projects keep hand-written files in the same folder.
|
|
53
|
+
if (!ours(site)) {
|
|
54
|
+
const fix = remove ? '' : ` For ${pretty}, remove that file or rename this site.`;
|
|
55
|
+
return { url: fallback, note: `${site} was not made by claudecraft, so it was left alone.${fix}` };
|
|
56
|
+
}
|
|
57
|
+
const live = !testDir && (await adminAnswers());
|
|
58
|
+
|
|
59
|
+
/** caddy validate|reload on the brew Caddyfile: '' when it worked, else Caddy's last log message. */
|
|
60
|
+
const caddy = (/** @type {string} */ command) => {
|
|
61
|
+
const result = spawnSync('caddy', [command, '--config', caddyfile], { encoding: 'utf8' });
|
|
62
|
+
if (result.status === 0) return '';
|
|
63
|
+
const last = (result.stderr ?? '').trim().split('\n').at(-1) || `caddy ${command} failed`;
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(last).msg ?? last;
|
|
66
|
+
} catch {
|
|
67
|
+
return last;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (remove) {
|
|
72
|
+
rmSync(site, { force: true });
|
|
73
|
+
const failed = live && caddy('reload');
|
|
74
|
+
return { url: fallback, error: failed ? `Caddy reload failed: ${failed}` : '' };
|
|
75
|
+
}
|
|
76
|
+
if (!testDir && !live) {
|
|
77
|
+
return { url: fallback, note: `Caddy is not running. For ${pretty}: brew services start caddy` };
|
|
78
|
+
}
|
|
79
|
+
const include = `import ${caddyDir}/*.caddy`;
|
|
80
|
+
if (!testDir && !readFileSync(caddyfile, 'utf8').includes(include)) {
|
|
81
|
+
return { url: fallback, note: `For ${pretty}, add this line to ${caddyfile}: ${include}` };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Caddy listens on every interface, so the guard keeps the site on this Mac. Vite listens on
|
|
85
|
+
// ::1, so the upstream is localhost (never 127.0.0.1) and the port is a literal number.
|
|
86
|
+
mkdirSync(caddyDir, { recursive: true });
|
|
87
|
+
writeFileSync(
|
|
88
|
+
site,
|
|
89
|
+
`# Generated by ${fileURLToPath(import.meta.url)} — do not edit by hand.
|
|
90
|
+
${name}.localhost {
|
|
91
|
+
\ttls internal
|
|
92
|
+
\t@offbox not remote_ip 127.0.0.1 ::1
|
|
93
|
+
\tabort @offbox
|
|
94
|
+
\treverse_proxy localhost:${devPort}
|
|
95
|
+
}
|
|
96
|
+
`,
|
|
97
|
+
);
|
|
98
|
+
const failed = !testDir && (caddy('validate') || caddy('reload'));
|
|
99
|
+
if (failed) {
|
|
100
|
+
rmSync(site, { force: true });
|
|
101
|
+
return { url: fallback, error: `Caddy refused ${site}: ${failed}` };
|
|
102
|
+
}
|
|
103
|
+
return { url: pretty };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** True when the brew Caddy's admin API answers, i.e. Caddy is running. */
|
|
107
|
+
async function adminAnswers() {
|
|
108
|
+
try {
|
|
109
|
+
const response = await fetch('http://localhost:2019/config/', { signal: AbortSignal.timeout(2000) });
|
|
110
|
+
await response.body?.cancel();
|
|
111
|
+
return true;
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Post-build: write index.md beside every indexable index.html, then llms.txt and
|
|
2
|
+
// llms-full.txt from those same pages, grouped by language. A request that prefers
|
|
3
|
+
// text/markdown gets a page's index.md from functions/_middleware.js.
|
|
4
|
+
//
|
|
5
|
+
// Three attributes shape an element's markdown without changing what a visitor sees:
|
|
6
|
+
// data-md="skip" left out (the options a picker hides)
|
|
7
|
+
// data-md-label="Mac" a bold line before the element (which case a command is for)
|
|
8
|
+
// data-md-text="a: b" the element's whole text (a row drawn as separate columns)
|
|
9
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { NodeHtmlMarkdown } from 'node-html-markdown';
|
|
13
|
+
import { locales, siteName, siteUrl } from '../site.config.mjs';
|
|
14
|
+
import { catalog, dist, distFiles, isNoindex, localeOf } from './shared.mjs';
|
|
15
|
+
|
|
16
|
+
const { parse } = createRequire(createRequire(import.meta.url).resolve('node-html-markdown'))(
|
|
17
|
+
'node-html-parser',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const DROP =
|
|
21
|
+
'[data-md="skip"], [aria-hidden="true"], [hidden], [role="img"], svg, script, style, noscript, template, dialog, img, picture, video, button, input, select, textarea';
|
|
22
|
+
// '<' is escaped as well, so a name like <Lab> stays text instead of becoming an HTML tag.
|
|
23
|
+
const markdown = new NodeHtmlMarkdown({
|
|
24
|
+
bulletMarker: '-',
|
|
25
|
+
maxConsecutiveNewlines: 2,
|
|
26
|
+
textReplace: [[/</g, '\\<']],
|
|
27
|
+
});
|
|
28
|
+
const yaml = (value) => JSON.stringify(value);
|
|
29
|
+
const escapeHtml = (text) => text.replace(/[&<>"]/g, (char) => `&#${char.charCodeAt(0)};`);
|
|
30
|
+
/** Backslash-escapes markdown syntax in names and descriptions spliced into llms.txt / llms-full.txt. */
|
|
31
|
+
const escapeMd = (text) => text.replace(/[\\`*_[\]<>]/g, '\\$&');
|
|
32
|
+
/** Moves a twin's headings under its page's ### heading in llms-full.txt; code fences are left alone. */
|
|
33
|
+
const demote = (md) => {
|
|
34
|
+
let fenced = false;
|
|
35
|
+
return md
|
|
36
|
+
.split('\n')
|
|
37
|
+
.map((line) => {
|
|
38
|
+
if (/^(```|~~~)/.test(line)) fenced = !fenced;
|
|
39
|
+
return !fenced && /^#{1,6} /.test(line) ? `###${line}`.replace(/^#{7,}/, '######') : line;
|
|
40
|
+
})
|
|
41
|
+
.join('\n');
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const pages = [];
|
|
45
|
+
|
|
46
|
+
for (const rel of await distFiles('index.html')) {
|
|
47
|
+
const file = join(dist, rel);
|
|
48
|
+
const html = await readFile(file, 'utf8');
|
|
49
|
+
if (isNoindex(html)) continue;
|
|
50
|
+
const headEnd = html.indexOf('</head>');
|
|
51
|
+
const head = parse(html.slice(0, headEnd === -1 ? 4000 : headEnd));
|
|
52
|
+
const lang = head.querySelector('html')?.getAttribute('lang');
|
|
53
|
+
const title = head.querySelector('title')?.text.trim();
|
|
54
|
+
const description = head.querySelector('meta[name="description"]')?.getAttribute('content')?.trim();
|
|
55
|
+
const canonical = head.querySelector('link[rel="canonical"]')?.getAttribute('href');
|
|
56
|
+
const main = html.match(/<main\b[^>]*>([\s\S]*)<\/main>/)?.[1];
|
|
57
|
+
if (!lang || !title || !description || !canonical || !main) {
|
|
58
|
+
throw new Error(`markdown-pages: ${file} lacks html lang, title, description, canonical, or <main>`);
|
|
59
|
+
}
|
|
60
|
+
const root = parse(main);
|
|
61
|
+
for (const node of root.querySelectorAll(DROP)) node.remove();
|
|
62
|
+
for (const node of root.querySelectorAll('[data-md-text]')) {
|
|
63
|
+
node.textContent = node.getAttribute('data-md-text');
|
|
64
|
+
}
|
|
65
|
+
for (const node of root.querySelectorAll('[data-md-label]')) {
|
|
66
|
+
node.insertAdjacentHTML(
|
|
67
|
+
'afterbegin',
|
|
68
|
+
`<p><strong>${escapeHtml(node.getAttribute('data-md-label'))}</strong></p>`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
// Root-relative links become absolute: a twin is read away from the page it describes.
|
|
72
|
+
for (const link of root.querySelectorAll('a[href^="/"]')) {
|
|
73
|
+
link.setAttribute('href', new URL(link.getAttribute('href'), siteUrl).href);
|
|
74
|
+
}
|
|
75
|
+
const body = markdown.translate(root.innerHTML).trim();
|
|
76
|
+
const md = [
|
|
77
|
+
'---',
|
|
78
|
+
`title: ${yaml(title)}`,
|
|
79
|
+
`description: ${yaml(description)}`,
|
|
80
|
+
`url: ${yaml(canonical)}`,
|
|
81
|
+
`lang: ${yaml(lang)}`,
|
|
82
|
+
'---',
|
|
83
|
+
'',
|
|
84
|
+
body,
|
|
85
|
+
'',
|
|
86
|
+
].join('\n');
|
|
87
|
+
await writeFile(file.replace(/index\.html$/, 'index.md'), md);
|
|
88
|
+
pages.push({
|
|
89
|
+
locale: localeOf(rel),
|
|
90
|
+
title,
|
|
91
|
+
description,
|
|
92
|
+
canonical,
|
|
93
|
+
twin: `${canonical}index.md`,
|
|
94
|
+
body,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
pages.sort((a, b) => a.canonical.localeCompare(b.canonical, 'en'));
|
|
99
|
+
const sections = locales.map((code) => ({
|
|
100
|
+
// A one-language site lists its pages without a language heading.
|
|
101
|
+
name: locales.length > 1 ? catalog(code).meta.name : 'Pages',
|
|
102
|
+
pages: pages.filter((p) => p.locale === code),
|
|
103
|
+
}));
|
|
104
|
+
const home = pages.find((page) => page.canonical === siteUrl);
|
|
105
|
+
if (!home) throw new Error(`markdown-pages: no indexable home page at ${siteUrl}`);
|
|
106
|
+
|
|
107
|
+
const llms = [
|
|
108
|
+
`# ${escapeMd(siteName)}`,
|
|
109
|
+
'',
|
|
110
|
+
`> ${escapeMd(home.description)}`,
|
|
111
|
+
'',
|
|
112
|
+
...sections.flatMap(({ name, pages }) => [
|
|
113
|
+
`## ${name}`,
|
|
114
|
+
'',
|
|
115
|
+
...pages.map(
|
|
116
|
+
(p) => `- [${escapeMd(p.title)}](${p.canonical}): ${escapeMd(p.description)} ([markdown](${p.twin}))`,
|
|
117
|
+
),
|
|
118
|
+
'',
|
|
119
|
+
]),
|
|
120
|
+
'## Optional',
|
|
121
|
+
'',
|
|
122
|
+
`- [llms-full.txt](${new URL('llms-full.txt', siteUrl).href}): every page above as markdown`,
|
|
123
|
+
`- [Sitemap](${new URL('sitemap-index.xml', siteUrl).href})`,
|
|
124
|
+
'',
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const full = [
|
|
128
|
+
`# ${escapeMd(siteName)}`,
|
|
129
|
+
'',
|
|
130
|
+
...sections.flatMap(({ name, pages }) => [
|
|
131
|
+
`## ${name}`,
|
|
132
|
+
'',
|
|
133
|
+
...pages.flatMap((p) => [`### [${escapeMd(p.title)}](${p.canonical})`, '', demote(p.body), '']),
|
|
134
|
+
]),
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
await writeFile(join(dist, 'llms.txt'), llms.join('\n'));
|
|
138
|
+
await writeFile(join(dist, 'llms-full.txt'), full.join('\n'));
|
|
139
|
+
|
|
140
|
+
console.log(
|
|
141
|
+
`markdown-pages: ${pages.length} page(s) in ${locales.length} language(s) + llms.txt + llms-full.txt`,
|
|
142
|
+
);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<!-- Share card for `npm run generate:og`, which fills the slots, colors, lang and dir from the site. -->
|
|
3
|
+
<html lang="en" dir="ltr">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<link rel="stylesheet" href="../node_modules/@fontsource/jetbrains-mono/400.css" />
|
|
7
|
+
<link rel="stylesheet" href="../node_modules/@fontsource/jetbrains-mono/700.css" />
|
|
8
|
+
<style>
|
|
9
|
+
:root {
|
|
10
|
+
--paper: #f4f1ea;
|
|
11
|
+
--ink: #1a1a18;
|
|
12
|
+
--accent: #1a1a18;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
* {
|
|
16
|
+
margin: 0;
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
body {
|
|
21
|
+
width: 1200px;
|
|
22
|
+
height: 630px;
|
|
23
|
+
padding: 88px 96px;
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
align-items: flex-start;
|
|
27
|
+
background: var(--paper);
|
|
28
|
+
color: var(--ink);
|
|
29
|
+
font-family: 'JetBrains Mono', ui-monospace, monospace;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Same reason as global.css: no Arabic, Hebrew, Devanagari or CJK in JetBrains Mono. */
|
|
33
|
+
[data-font='system'] body {
|
|
34
|
+
font-family: system-ui, sans-serif;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.rule {
|
|
38
|
+
width: 120px;
|
|
39
|
+
height: 8px;
|
|
40
|
+
background: var(--accent);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
h1,
|
|
44
|
+
p {
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
display: -webkit-box;
|
|
47
|
+
-webkit-box-orient: vertical;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
h1 {
|
|
51
|
+
margin-top: auto;
|
|
52
|
+
font-size: 80px;
|
|
53
|
+
line-height: 1.05;
|
|
54
|
+
letter-spacing: -0.02em;
|
|
55
|
+
-webkit-line-clamp: 2;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
p {
|
|
59
|
+
margin-top: 28px;
|
|
60
|
+
max-width: 36ch;
|
|
61
|
+
font-size: 30px;
|
|
62
|
+
line-height: 1.4;
|
|
63
|
+
color: color-mix(in oklab, var(--ink) 72%, var(--paper));
|
|
64
|
+
-webkit-line-clamp: 3;
|
|
65
|
+
}
|
|
66
|
+
</style>
|
|
67
|
+
</head>
|
|
68
|
+
<body>
|
|
69
|
+
<div class="rule"></div>
|
|
70
|
+
<h1 data-slot="name"></h1>
|
|
71
|
+
<p data-slot="description"></p>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Node-side helpers for astro.config.mjs and the scripts in this folder.
|
|
2
|
+
// Pages and layouts read the language files through src/i18n/index.ts instead.
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { readdir } from 'node:fs/promises';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { defaultLocale, locales } from '../site.config.mjs';
|
|
7
|
+
|
|
8
|
+
export const dist = fileURLToPath(new URL('../dist/', import.meta.url));
|
|
9
|
+
|
|
10
|
+
/** src/i18n/<code>.json, parsed. */
|
|
11
|
+
export const catalog = (code) =>
|
|
12
|
+
JSON.parse(readFileSync(new URL(`../src/i18n/${code}.json`, import.meta.url), 'utf8'));
|
|
13
|
+
|
|
14
|
+
/** The locale of a dist-relative path: its first segment, or the unprefixed default. */
|
|
15
|
+
export const localeOf = (rel) => {
|
|
16
|
+
const first = rel.split('/')[0];
|
|
17
|
+
return first !== defaultLocale && locales.includes(first) ? first : defaultLocale;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** BaseLayout's noindex tag: the one switch for the sitemap, llms.txt and markdown twins. */
|
|
21
|
+
export const isNoindex = (html) => /<meta name="robots" content="noindex/.test(html);
|
|
22
|
+
|
|
23
|
+
/** dist-relative paths (with /) of every file called `name`, e.g. 'index.html'. */
|
|
24
|
+
export const distFiles = async (name) =>
|
|
25
|
+
(await readdir(dist, { recursive: true }))
|
|
26
|
+
.map((rel) => rel.replaceAll('\\', '/'))
|
|
27
|
+
.filter((rel) => rel === name || rel.endsWith(`/${name}`));
|
|
28
|
+
|
|
29
|
+
/** A --color-<name> token value from src/styles/global.css, or undefined. */
|
|
30
|
+
export const cssColor = (name) =>
|
|
31
|
+
readFileSync(new URL('../src/styles/global.css', import.meta.url), 'utf8')
|
|
32
|
+
.match(new RegExp(`--color-${name}:\\s*([^;{}<]+);`))?.[1]
|
|
33
|
+
.trim();
|