Skip to content

Commit 018601c

Browse files
committed
chore(dev): replace preview fixture with local demo site
1 parent 8352b5f commit 018601c

62 files changed

Lines changed: 154 additions & 443 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr-preview-build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ jobs:
6060
- name: Build Theme Assets
6161
run: pnpm run build
6262

63+
- name: Link Local Theme
64+
run: node dev/link-theme.mjs
65+
6366
- name: Build Hexo Site
64-
run: pnpm run preview:generate -- --output-dir dev/site/public
67+
run: pnpm --dir dev/site exec hexo generate
6568

6669
- name: Prepare Vercel Prebuilt Output
6770
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ yarn.lock
2929
/.sass-cache
3030
/dev/site/db.json
3131
/dev/site/public
32+
/dev/site/themes
3233
/dev/site/.source
3334
/dev/site/node_modules
3435
/connect.lock

.zed/tasks.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,5 @@
1717
"use_new_terminal": true,
1818
"reveal": "always",
1919
"save": "all"
20-
},
21-
{
22-
"label": "Redefine preview generate",
23-
"command": "pnpm",
24-
"args": ["run", "preview:generate"],
25-
"cwd": "$ZED_WORKTREE_ROOT",
26-
"reveal": "always",
27-
"save": "all"
2820
}
2921
]

AGENTS.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ This file is for automated coding agents working in this repo.
1818
- Build CSS only: `pnpm run build:css` (Tailwind CLI).
1919
- Build JS only: `pnpm run build:js` (minifies into `source/js/build`).
2020
- Watch CSS: `pnpm run watch:css`.
21-
- Develop against the current worktree: `pnpm dev`.
22-
- Generate the preview fixture: `pnpm run preview:generate`.
21+
- Develop against the local demo site: `pnpm dev`.
2322
- Pre-commit hook blocks committing build outputs on non-`main`/`dev` branches (see `.husky/pre-commit`).
2423
- Lint: no npm script or config present; add one if needed.
2524
- Tests: no test runner configured.
@@ -62,11 +61,11 @@ This file is for automated coding agents working in this repo.
6261
- Class naming: favor existing kebab-case classes and theme-specific names.
6362
- Tailwind source lives in `source/css/tailwind.source.css`; never edit the generated file.
6463

65-
## Preview Fixture
64+
## Demo Site
6665
- The local Hexo site lives in `dev/site/` and is a private pnpm workspace package.
67-
- `dev/preview.mjs` runs Hexo against the current theme worktree through an isolated temporary runtime.
66+
- `dev/dev.mjs` mounts the current theme into the demo site, runs Hexo, and watches CSS changes.
6867
- Branch-specific validation posts and demo pages belong under `dev/site`.
69-
- Native dependencies required by the fixture are explicitly allowed in `pnpm-workspace.yaml`.
68+
- Native dependencies required by the demo site are explicitly allowed in `pnpm-workspace.yaml`.
7069

7170
## Configuration/Data Flow
7271
- `_config.yml` is the theme config; new options should be exported in `scripts/config-export.js`.

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,24 @@ It's very easy to understand.
117117
## 🛠️ Theme Development
118118

119119
Open the theme repository itself in your editor. Zed worktrees are independent
120-
theme checkouts, and each checkout contains the Hexo preview fixture under
121-
`dev/site`.
120+
theme checkouts, and each checkout contains the local demo site under `dev/site`.
122121

123122
Install all local dependencies with pnpm:
124123

125124
```sh
126125
pnpm install --frozen-lockfile
127126
```
128127

129-
Start Hexo with the current theme worktree:
128+
Start the local demo site with the current theme worktree:
130129

131130
```sh
132131
pnpm dev
133132
```
134133

135-
Generate the fixture without starting a server:
136-
137-
```sh
138-
pnpm run preview:generate
139-
```
140-
141-
Issue-specific posts and demo pages belong under `dev/site` and can be
142-
committed with the theme branch that needs them. The fixture is excluded from
143-
the published npm package. npm remains supported for installing the published
144-
theme; pnpm is the repository development and CI package manager.
134+
Demo posts and pages belong under `dev/site` and can be committed with the
135+
theme branch that needs them. The demo site is excluded from the published npm
136+
package. npm remains supported for installing the published theme; pnpm is the
137+
repository development and CI package manager.
145138

146139

147140

dev/dev.mjs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import path from "path";
2+
import { spawn } from "child_process";
3+
import { fileURLToPath } from "url";
4+
import { linkTheme } from "./link-theme.mjs";
5+
6+
const SCRIPT_PATH = fileURLToPath(import.meta.url);
7+
const THEME_ROOT = path.resolve(path.dirname(SCRIPT_PATH), "..");
8+
const SITE_ROOT = path.join(THEME_ROOT, "dev", "site");
9+
const HEXO_PATH = path.join(SITE_ROOT, "node_modules", ".bin", "hexo");
10+
11+
const children = [];
12+
let shuttingDown = false;
13+
14+
const shutdown = (exitCode = 0) => {
15+
if (shuttingDown) return;
16+
shuttingDown = true;
17+
children.forEach((child) => {
18+
if (!child.killed) child.kill("SIGTERM");
19+
});
20+
process.exitCode = exitCode;
21+
};
22+
23+
const start = (command, args, cwd) => {
24+
const child = spawn(command, args, {
25+
cwd,
26+
env: { ...process.env, HUSKY: "0", NODE_ENV: "development" },
27+
stdio: "inherit",
28+
});
29+
children.push(child);
30+
return child;
31+
};
32+
33+
const main = () => {
34+
linkTheme();
35+
const hexo = start(HEXO_PATH, ["server", ...process.argv.slice(2)], SITE_ROOT);
36+
const css = start("pnpm", ["run", "watch:css"], THEME_ROOT);
37+
38+
hexo.on("exit", (code) => {
39+
if (!shuttingDown) shutdown(code || 0);
40+
});
41+
css.on("exit", (code) => {
42+
if (!shuttingDown && code !== 0) shutdown(code || 1);
43+
});
44+
45+
process.on("SIGINT", () => shutdown());
46+
process.on("SIGTERM", () => shutdown());
47+
48+
console.log("Demo site -> http://127.0.0.1:4000");
49+
};
50+
51+
main();

dev/link-theme.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
5+
const SCRIPT_PATH = fileURLToPath(import.meta.url);
6+
const THEME_ROOT = path.resolve(path.dirname(SCRIPT_PATH), "..");
7+
const SITE_ROOT = path.join(THEME_ROOT, "dev", "site");
8+
const THEME_LINK = path.join(SITE_ROOT, "themes", "redefine");
9+
const THEME_ENTRIES = [
10+
"_config.yml",
11+
"languages",
12+
"layout",
13+
"package.json",
14+
"scripts",
15+
"source",
16+
];
17+
18+
export const linkTheme = () => {
19+
fs.rmSync(THEME_LINK, { recursive: true, force: true });
20+
fs.mkdirSync(THEME_LINK, { recursive: true });
21+
22+
THEME_ENTRIES.forEach((entry) => {
23+
const target = path.join(THEME_ROOT, entry);
24+
const linkPath = path.join(THEME_LINK, entry);
25+
const type = fs.statSync(target).isDirectory()
26+
? process.platform === "win32"
27+
? "junction"
28+
: "dir"
29+
: "file";
30+
fs.symlinkSync(target, linkPath, type);
31+
});
32+
};
33+
34+
if (path.resolve(process.argv[1] || "") === SCRIPT_PATH) linkTheme();

0 commit comments

Comments
 (0)