@xingwangzhe/stalux 1.7.8 → 1.7.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingwangzhe/stalux",
3
- "version": "1.7.8",
3
+ "version": "1.7.9",
4
4
  "description": "A powerful, modern Astro blog theme — use as template or install as plugin",
5
5
  "keywords": [
6
6
  "astro",
package/src/i18n/en.json CHANGED
@@ -136,7 +136,7 @@
136
136
  "author": "xingwangzhe",
137
137
  "copyright": "© xingwangzhe. All rights reserved.",
138
138
  "certNumber": "Software Copyright No. 16914672",
139
- "certUrl": "https://stalux.needhelp.icu/软著证明.pdf",
139
+ "certUrl": "/软著证明.pdf",
140
140
  "regDate": "2025-11-24",
141
141
  "labelVersion": "📦 Version: ",
142
142
  "labelAuthor": "👤 Author: ",
@@ -136,7 +136,7 @@
136
136
  "author": "王兴家 (xingwangzhe)",
137
137
  "copyright": "© 王兴家. All rights reserved.",
138
138
  "certNumber": "软著登字第16914672号",
139
- "certUrl": "https://stalux.needhelp.icu/软著证明.pdf",
139
+ "certUrl": "/软著证明.pdf",
140
140
  "regDate": "2025年11月24日",
141
141
  "labelVersion": "📦 版本:",
142
142
  "labelAuthor": "👤 著作权人:",
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * 基于 Astro 7.1.3 Integration API(astro:config:setup / injectRoute / injectScript)
9
9
  */
10
10
 
11
- import { existsSync, readdirSync } from "node:fs";
11
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
12
12
  import path from "node:path";
13
13
  import { resolve } from "node:path";
14
14
  import { fileURLToPath } from "node:url";
@@ -143,7 +143,7 @@ export function stalux(options: StaluxOptions = {}): AstroIntegration {
143
143
  injectScript,
144
144
  updateConfig,
145
145
  addDevToolbarApp,
146
- _config,
146
+ config,
147
147
  logger,
148
148
  }) => {
149
149
  const srcDir = fileURLToPath(new URL(".", import.meta.url));
@@ -191,7 +191,45 @@ export function stalux(options: StaluxOptions = {}): AstroIntegration {
191
191
 
192
192
  logger.info(`Stalux initialized (contentDir: ${opt.contentDir})`);
193
193
 
194
- // 5. 字体裁剪(在 config:setup 阶段执行,保证 dev/build 都能生成)
194
+ // 5. 站点 URL 单源化:以 stalux/config/site.yml 的 url 为准
195
+ // sitemap 与 context.site 都派生自 astro.config 的 site 字段,
196
+ // 这里在构建前将其与主题配置对齐,避免输出与配置不一致的 URL
197
+ // (例如 README 里的 https://example.com 占位、或用户只改了 site.yml 忘了改 astro.config)。
198
+ try {
199
+ const contentDir = opt.contentDir ?? "stalux";
200
+ const siteYamlPath = path.resolve(
201
+ process.cwd(),
202
+ contentDir,
203
+ "config",
204
+ "site.yml",
205
+ );
206
+ const siteYaml = readFileSync(siteYamlPath, "utf-8");
207
+ const urlMatch = siteYaml.match(/^url\s*:\s*(.+)$/m);
208
+ const yamlUrl = urlMatch?.[1]
209
+ .trim()
210
+ .replace(/^["']|["']$/g, "")
211
+ .replace(/\/+$/, "");
212
+ if (yamlUrl) {
213
+ const configuredSite = config.site?.replace(/\/+$/, "");
214
+ if (!configuredSite || configuredSite === "https://example.com") {
215
+ // 未配置或为占位符 → 直接以 site.yml 为准
216
+ updateConfig({ site: yamlUrl });
217
+ logger.info(
218
+ `Stalux: site set to ${yamlUrl} (from ${contentDir}/config/site.yml)`,
219
+ );
220
+ } else if (configuredSite !== yamlUrl) {
221
+ // 用户显式配置了不同的域名 → 保留用户配置,但提示差异
222
+ logger.warn(
223
+ `Stalux: astro.config site (${configuredSite}) 与 ${contentDir}/config/site.yml 的 url (${yamlUrl}) 不一致。` +
224
+ "sitemap 将使用 astro.config 的 site,llms.txt / *.md 导出将使用 site.yml 的 url,请统一二者。",
225
+ );
226
+ }
227
+ }
228
+ } catch {
229
+ logger.debug("Stalux: site.yml not found, skip site sync");
230
+ }
231
+
232
+ // 6. 字体裁剪(在 config:setup 阶段执行,保证 dev/build 都能生成)
195
233
  try {
196
234
  const projectRoot = process.cwd();
197
235
  await runFontSubsetting(projectRoot, logger, true);
@@ -201,7 +239,7 @@ export function stalux(options: StaluxOptions = {}): AstroIntegration {
201
239
  },
202
240
 
203
241
  "astro:build:start": async ({ logger }) => {
204
- // 6. 字体裁剪(构建时,生成全部路由子集)
242
+ // 7. 字体裁剪(构建时,生成全部路由子集)
205
243
  try {
206
244
  const projectRoot = process.cwd();
207
245
  await runFontSubsetting(projectRoot, logger);
@@ -211,7 +249,7 @@ export function stalux(options: StaluxOptions = {}): AstroIntegration {
211
249
  },
212
250
 
213
251
  "astro:server:setup": async ({ server, logger }) => {
214
- // 7. 字体裁剪(开发模式,生成 common 子集 + 按需路由切片)
252
+ // 8. 字体裁剪(开发模式,生成 common 子集 + 按需路由切片)
215
253
  try {
216
254
  const projectRoot = process.cwd();
217
255
  // 清除旧的字体缓存
@@ -49,10 +49,16 @@ function getSiteConfig(config: ConfigMap): Record<string, unknown> {
49
49
  return config.get("site") ?? {};
50
50
  }
51
51
 
52
- /** 解析站点根 URL */
52
+ /**
53
+ * 解析站点根 URL。
54
+ *
55
+ * 唯一真源是 stalux/config/site.yml 的 url;context.site(astro.config.mjs 的 site)
56
+ * 仅作为 site.yml 缺失时的兜底,避免 llms.txt / *.md 导出与 sitemap / canonical 输出不一致。
57
+ */
53
58
  export function getSite(config: ConfigMap, contextSite?: string): string {
54
59
  const siteData = getSiteConfig(config);
55
- return (contextSite || (siteData.url as string) || "").replace(/\/$/, "");
60
+ const configUrl = siteData.url as string | undefined;
61
+ return (configUrl || contextSite || "").replace(/\/$/, "");
56
62
  }
57
63
 
58
64
  /** 将任意空白压缩为单行 */