hd-garden 0.3.7 → 0.3.8

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/.env.example CHANGED
@@ -8,11 +8,14 @@ ADMIN_URL=https://admin.example.com
8
8
  # 可选:反向代理或多域名后台时,显式指定 GitHub OAuth 回调地址。
9
9
  # GITHUB_OAUTH_REDIRECT_URI=https://admin.example.com/api/auth/github/callback
10
10
 
11
- # Giscus:在 https://giscus.app 配置后复制以下四项。
12
- GISCUS_REPO=owner/repository
13
- GISCUS_REPO_ID=R_xxxxxxxxxx
14
- GISCUS_CATEGORY=Announcements
15
- GISCUS_CATEGORY_ID=DIC_xxxxxxxxxx
11
+ # 评论默认关闭。打开 https://giscus.app/zh-CN 安装后,去掉注释并填入真实值。
12
+ # 仓库必须是 owner/name 这种公开仓库,且已开启 Discussions。
13
+ # 线上还要把同名四项写进 GitHub Actions Variables。留空会让发布失败。
14
+ # 确定不开放评论时,把 Actions Variable GISCUS_DISABLED 设为 1。
15
+ # GISCUS_REPO=
16
+ # GISCUS_REPO_ID=
17
+ # GISCUS_CATEGORY=
18
+ # GISCUS_CATEGORY_ID=
16
19
 
17
20
  # Webmention.io:注册正式域名后填写域名,不含 https://。
18
21
  WEBMENTION_IO_DOMAIN=example.com
package/Makefile CHANGED
@@ -26,7 +26,6 @@ skill:
26
26
 
27
27
  prepare:
28
28
  @if [ ! -d node_modules ]; then npm ci; fi
29
- @if [ ! -f .env.local ]; then cp .env.example .env.local; fi
30
29
 
31
30
  dev: prepare
32
31
  node bin/garden.mjs dev
package/README.md CHANGED
@@ -55,11 +55,11 @@ make update # 检查、提交并触发自动发布
55
55
  make update MESSAGE="新增一篇文章"
56
56
  ```
57
57
 
58
- `make dev` 会在首次运行时自动安装依赖并创建 `.env.local`。`make update` 会先检查,再提交并推送工作区中的所有改动。不想发布的文件请先移出仓库或加入 `.gitignore`。
58
+ `make dev` 会在首次运行时自动安装依赖并创建 `.env.local`,同时说明如何接上评论。线上发布要求 Actions Variables 里有 `GISCUS_REPO`、`GISCUS_REPO_ID`、`GISCUS_CATEGORY`、`GISCUS_CATEGORY_ID`;留空会让构建失败。确定不开放评论时设置 `GISCUS_DISABLED=1`。`make update` 会先检查,再提交并推送工作区中的所有改动。不想发布的文件请先移出仓库或加入 `.gitignore`。
59
59
 
60
60
  ## 进一步配置
61
61
 
62
- 首次跑通以后,再按需查看:
62
+ 评论接法见[从零开始](docs/quick-start.md)。跑通以后,再按需查看:
63
63
 
64
64
  - [评论、Webmentions 与内容分发](docs/integrations.md)
65
65
  - [随想管理后台](docs/admin-service.md)
@@ -1,29 +1,9 @@
1
1
  import { ChatCircle, GithubLogo } from "@phosphor-icons/react/ssr";
2
- import {
3
- GiscusComments,
4
- type GiscusConfig,
5
- } from "./GiscusComments";
6
-
7
- function giscusConfig(): GiscusConfig | undefined {
8
- const config = {
9
- repo:
10
- process.env.GISCUS_REPO ?? process.env.NEXT_PUBLIC_GISCUS_REPO,
11
- repoId:
12
- process.env.GISCUS_REPO_ID ?? process.env.NEXT_PUBLIC_GISCUS_REPO_ID,
13
- category:
14
- process.env.GISCUS_CATEGORY ??
15
- process.env.NEXT_PUBLIC_GISCUS_CATEGORY,
16
- categoryId:
17
- process.env.GISCUS_CATEGORY_ID ??
18
- process.env.NEXT_PUBLIC_GISCUS_CATEGORY_ID,
19
- };
20
- return Object.values(config).every(Boolean)
21
- ? (config as GiscusConfig)
22
- : undefined;
23
- }
2
+ import { readGiscusConfig } from "../lib/giscus-config";
3
+ import { GiscusComments } from "./GiscusComments";
24
4
 
25
5
  export function Comments({ slug }: { slug: string }) {
26
- const config = giscusConfig();
6
+ const config = readGiscusConfig();
27
7
 
28
8
  return (
29
9
  <section className="comments" aria-labelledby={`comments-heading-${slug}`}>
@@ -34,7 +14,7 @@ export function Comments({ slug }: { slug: string }) {
34
14
  <p>
35
15
  {config
36
16
  ? "评论由 GitHub Discussions 保存和管理。"
37
- : "评论接入已准备好,补充 GitHub Discussions 配置后即可开放。"}
17
+ : "评论还没开放。配好下面四项后,这里才会出现评论框。"}
38
18
  </p>
39
19
  </div>
40
20
  </div>
@@ -45,8 +25,14 @@ export function Comments({ slug }: { slug: string }) {
45
25
  <div className="integration-notice">
46
26
  <GithubLogo size={20} weight="fill" />
47
27
  <p>
48
- 需要一个公开 GitHub 仓库,并为它启用 Discussions、安装 Giscus
49
- App、选择评论分类。
28
+ 打开{" "}
29
+ <a href="https://giscus.app/zh-CN" target="_blank" rel="noreferrer">
30
+ Giscus
31
+ </a>
32
+ ,安装到一个已开启 Discussions 的公开仓库,把仓库、仓库 ID、分类、分类 ID
33
+ 写入 <code>.env.local</code> 和 GitHub Actions Variables:
34
+ <code>GISCUS_REPO</code>、<code>GISCUS_REPO_ID</code>、
35
+ <code>GISCUS_CATEGORY</code>、<code>GISCUS_CATEGORY_ID</code>。
50
36
  </p>
51
37
  </div>
52
38
  )}
@@ -2,12 +2,9 @@
2
2
 
3
3
  import { useEffect, useRef } from "react";
4
4
 
5
- export type GiscusConfig = {
6
- repo: string;
7
- repoId: string;
8
- category: string;
9
- categoryId: string;
10
- };
5
+ import type { GiscusConfig } from "../lib/giscus-config";
6
+
7
+ export type { GiscusConfig };
11
8
 
12
9
  function currentGiscusTheme() {
13
10
  return document.documentElement.dataset.theme === "dark" ? "dark" : "light";
package/app/globals.css CHANGED
@@ -2934,6 +2934,17 @@ button {
2934
2934
  font-size: 11px;
2935
2935
  }
2936
2936
 
2937
+ .integration-notice a,
2938
+ .integration-notice code {
2939
+ text-decoration: underline;
2940
+ text-underline-offset: 0.18em;
2941
+ }
2942
+
2943
+ .integration-notice code {
2944
+ text-decoration: none;
2945
+ font-family: var(--font-mono), ui-monospace, monospace;
2946
+ }
2947
+
2937
2948
  .integration-status {
2938
2949
  margin: 22px 0 0;
2939
2950
  color: var(--muted);
@@ -0,0 +1,39 @@
1
+ export type GiscusConfig = {
2
+ repo: string;
3
+ repoId: string;
4
+ category: string;
5
+ categoryId: string;
6
+ };
7
+
8
+ const PLACEHOLDERS = new Set([
9
+ "owner/repository",
10
+ "R_xxxxxxxxxx",
11
+ "DIC_xxxxxxxxxx",
12
+ ]);
13
+
14
+ function configuredValue(
15
+ env: Record<string, string | undefined>,
16
+ primary: string,
17
+ fallback: string,
18
+ ) {
19
+ const value = (env[primary] ?? env[fallback] ?? "").trim();
20
+ if (!value || PLACEHOLDERS.has(value)) return undefined;
21
+ return value;
22
+ }
23
+
24
+ export function readGiscusConfig(
25
+ env: Record<string, string | undefined> = process.env,
26
+ ): GiscusConfig | undefined {
27
+ const repo = configuredValue(env, "GISCUS_REPO", "NEXT_PUBLIC_GISCUS_REPO");
28
+ const repoId = configuredValue(env, "GISCUS_REPO_ID", "NEXT_PUBLIC_GISCUS_REPO_ID");
29
+ const category = configuredValue(env, "GISCUS_CATEGORY", "NEXT_PUBLIC_GISCUS_CATEGORY");
30
+ const categoryId = configuredValue(
31
+ env,
32
+ "GISCUS_CATEGORY_ID",
33
+ "NEXT_PUBLIC_GISCUS_CATEGORY_ID",
34
+ );
35
+ if (!repo || !repoId || !category || !categoryId) return undefined;
36
+ if (!/^[^/\s]+\/[^/\s]+$/.test(repo)) return undefined;
37
+ if (!repoId.startsWith("R_") || !categoryId.startsWith("DIC_")) return undefined;
38
+ return { repo, repoId, category, categoryId };
39
+ }
package/bin/garden.mjs CHANGED
@@ -88,11 +88,25 @@ function ensurePublic() {
88
88
  }
89
89
  }
90
90
 
91
+ function printGiscusGuide() {
92
+ process.stdout.write(`评论默认关闭。发布前要接上自己的 Giscus,留空会让 GitHub Actions 构建失败:
93
+ 1. 准备一个公开 GitHub 仓库,并开启 Discussions。公开源码仓库可以直接用;私有源码要另建一个公开仓库。
94
+ 2. 打开 https://giscus.app/zh-CN ,安装 Giscus App,只授权这个仓库,并选一个分类。
95
+ 3. 把仓库、仓库 ID、分类、分类 ID 写入 .env.local 的 GISCUS_REPO、GISCUS_REPO_ID、GISCUS_CATEGORY、GISCUS_CATEGORY_ID。
96
+ 4. 在源码仓库 Settings → Secrets and variables → Actions → Variables 写入同样四项。
97
+ 示例值不会被当成已配置。确定不开放评论时,把 Actions Variable GISCUS_DISABLED 设为 1。
98
+ `);
99
+ }
100
+
91
101
  function ensureEnv() {
102
+ // CI injects the real values. Copying .env.example there would fill any
103
+ // unset key with a sample, which used to turn comments on for owner/repository.
104
+ if (process.env.GITHUB_ACTIONS === "true") return;
92
105
  const example = path.join(gardenPackageRoot, ".env.example");
93
106
  const local = path.join(siteRoot, ".env.local");
94
107
  if (!fs.existsSync(local) && fs.existsSync(example)) {
95
108
  fs.copyFileSync(example, local);
109
+ printGiscusGuide();
96
110
  }
97
111
  }
98
112
 
@@ -241,8 +255,10 @@ function initSite() {
241
255
  process.stdout.write("下一步:\n");
242
256
  process.stdout.write(` cd ${destination}\n`);
243
257
  process.stdout.write(" npm install\n");
258
+ process.stdout.write(" 按下面四步接上评论,再写文章\n");
244
259
  process.stdout.write(" make new TITLE=\"你好,世界\" SLUG=hello\n");
245
260
  process.stdout.write(" make dev\n");
261
+ printGiscusGuide();
246
262
  }
247
263
 
248
264
  function packagedSkills() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hd-garden",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "private": false,
5
5
  "description": "用 Markdown 写作、用 GitHub Pages 发布的个人博客引擎。",
6
6
  "license": "MIT",
@@ -8,6 +8,8 @@ make new TITLE="你好,世界" SLUG=hello
8
8
  make dev
9
9
  ```
10
10
 
11
- 第一次 `npx garden dev` 会补齐 Makefile 和 skill。Cursor / Codex 打开这个仓库后会读到 `.agents/skills/`。要更新 skill,再运行 `npx garden skill`。
11
+ 第一次 `npx garden dev` 会补齐 Makefile 和 skill,并创建 `.env.local`。Cursor / Codex 打开这个仓库后会读到 `.agents/skills/`。要更新 skill,再运行 `npx garden skill`。
12
+
13
+ 评论默认关闭。发布前打开 [Giscus](https://giscus.app/zh-CN),把仓库、仓库 ID、分类、分类 ID 写入 `.env.local`,并在 GitHub Actions Variables 设置同名的 `GISCUS_REPO`、`GISCUS_REPO_ID`、`GISCUS_CATEGORY`、`GISCUS_CATEGORY_ID`。留空会让发布失败。确定不开放评论时,把 `GISCUS_DISABLED` 设为 `1`。
12
14
 
13
15
  升级引擎:把 `package.json` 里的 `hd-garden` 改到新版本,例如 `^0.4.0`,再运行 `npm install`。