@sugarat/theme 0.5.17 → 0.5.18

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/node.js CHANGED
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(node_exports);
40
40
  // src/utils/node/mdPlugins.ts
41
41
  var import_module = require("module");
42
42
 
43
- // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.7.3_vitepress@2.0.0-alpha.16_@types+node@24.5.2_async-validator@4.2.5_wszfouv2xxx6bizfwwcmbwut3e/node_modules/vitepress-plugin-tabs/dist/node/index.js
43
+ // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.7.3_vitepress@2.0.0-alpha.17_@types+node@24.5.2_async-validator_91c0bbe99a18f826c198452196112f9a/node_modules/vitepress-plugin-tabs/dist/node/index.js
44
44
  function container_plugin(md, name, options) {
45
45
  function validateDefault(params) {
46
46
  return params.trim().split(" ", 2)[0] === name;
@@ -637,6 +637,27 @@ function patchGroupIconPlugin() {
637
637
  }
638
638
  });
639
639
  }
640
+ function extractDefaultExportString(info) {
641
+ const ast = info.ast;
642
+ try {
643
+ if (ast && Array.isArray(ast.body)) {
644
+ for (const node of ast.body) {
645
+ if (node.type === "ExportDefaultDeclaration") {
646
+ const decl = node.declaration;
647
+ if (decl?.type === "Literal" && typeof decl.value === "string") {
648
+ return decl.value;
649
+ }
650
+ if (decl?.type === "TemplateLiteral" && (decl.expressions?.length ?? 0) === 0) {
651
+ return decl.quasis?.[0]?.value?.cooked;
652
+ }
653
+ }
654
+ }
655
+ }
656
+ } catch (_) {
657
+ }
658
+ const m = info.code?.match(/export\s+default\s+(['"`])([\s\S]*?)\1/);
659
+ return m?.[2];
660
+ }
640
661
  function patchTabsPlugin() {
641
662
  return createPatchPlugin({
642
663
  name: "@sugarat/theme-plugin-patch-tabs",
@@ -722,8 +743,9 @@ function coverImgTransform() {
722
743
  if (!relativePathMap[info.id]) {
723
744
  return;
724
745
  }
725
- const asset = info.code?.match(/export default "(.*)"/)?.[1];
746
+ const asset = extractDefaultExportString(info);
726
747
  if (!asset) {
748
+ console.warn(`[coverImgTransform] \u89E3\u6790\u9ED8\u8BA4\u5BFC\u51FA\u5931\u8D25: ${info.id}`);
727
749
  return;
728
750
  }
729
751
  viteAssetsMap[info.id] = asset;
package/node.mjs CHANGED
@@ -9,7 +9,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
9
9
  // src/utils/node/mdPlugins.ts
10
10
  import { createRequire } from "module";
11
11
 
12
- // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.7.3_vitepress@2.0.0-alpha.16_@types+node@24.5.2_async-validator@4.2.5_wszfouv2xxx6bizfwwcmbwut3e/node_modules/vitepress-plugin-tabs/dist/node/index.js
12
+ // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.7.3_vitepress@2.0.0-alpha.17_@types+node@24.5.2_async-validator_91c0bbe99a18f826c198452196112f9a/node_modules/vitepress-plugin-tabs/dist/node/index.js
13
13
  function container_plugin(md, name, options) {
14
14
  function validateDefault(params) {
15
15
  return params.trim().split(" ", 2)[0] === name;
@@ -606,6 +606,27 @@ function patchGroupIconPlugin() {
606
606
  }
607
607
  });
608
608
  }
609
+ function extractDefaultExportString(info) {
610
+ const ast = info.ast;
611
+ try {
612
+ if (ast && Array.isArray(ast.body)) {
613
+ for (const node of ast.body) {
614
+ if (node.type === "ExportDefaultDeclaration") {
615
+ const decl = node.declaration;
616
+ if (decl?.type === "Literal" && typeof decl.value === "string") {
617
+ return decl.value;
618
+ }
619
+ if (decl?.type === "TemplateLiteral" && (decl.expressions?.length ?? 0) === 0) {
620
+ return decl.quasis?.[0]?.value?.cooked;
621
+ }
622
+ }
623
+ }
624
+ }
625
+ } catch (_) {
626
+ }
627
+ const m = info.code?.match(/export\s+default\s+(['"`])([\s\S]*?)\1/);
628
+ return m?.[2];
629
+ }
609
630
  function patchTabsPlugin() {
610
631
  return createPatchPlugin({
611
632
  name: "@sugarat/theme-plugin-patch-tabs",
@@ -691,8 +712,9 @@ function coverImgTransform() {
691
712
  if (!relativePathMap[info.id]) {
692
713
  return;
693
714
  }
694
- const asset = info.code?.match(/export default "(.*)"/)?.[1];
715
+ const asset = extractDefaultExportString(info);
695
716
  if (!asset) {
717
+ console.warn(`[coverImgTransform] \u89E3\u6790\u9ED8\u8BA4\u5BFC\u51FA\u5931\u8D25: ${info.id}`);
696
718
  return;
697
719
  }
698
720
  viteAssetsMap[info.id] = asset;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -51,14 +51,14 @@
51
51
  "vitepress-plugin-group-icons": "1.6.5",
52
52
  "vitepress-plugin-mermaid": "2.0.13",
53
53
  "vitepress-plugin-tabs": "0.7.3",
54
- "vitepress-plugin-announcement": "0.1.7",
55
54
  "@sugarat/theme-shared": "0.0.7",
55
+ "vitepress-plugin-back2top": "0.1.0",
56
+ "vitepress-plugin-announcement": "0.1.7",
56
57
  "vitepress-plugin-giscus": "0.1.0",
57
- "vitepress-plugin-image-preview": "0.1.1",
58
- "vitepress-plugin-rss": "0.4.3",
59
58
  "vitepress-plugin-artalk": "0.1.0",
60
- "vitepress-plugin-pagefind": "0.4.19",
61
- "vitepress-plugin-back2top": "0.1.0"
59
+ "vitepress-plugin-image-preview": "0.1.2",
60
+ "vitepress-plugin-rss": "0.4.3",
61
+ "vitepress-plugin-pagefind": "0.4.19"
62
62
  },
63
63
  "devDependencies": {
64
64
  "artalk": "^2.8.5",
@@ -66,7 +66,7 @@
66
66
  "pagefind": "^1.3.0",
67
67
  "typescript": "^5.4.5",
68
68
  "vite": "^5.4.9",
69
- "vitepress": "2.0.0-alpha.16",
69
+ "vitepress": "2.0.0-alpha.17",
70
70
  "vue": "^3.5.24",
71
71
  "vitepress-plugin-51la": "0.1.1"
72
72
  },
@@ -117,6 +117,32 @@ export function patchGroupIconPlugin() {
117
117
  })
118
118
  }
119
119
 
120
+ export function extractDefaultExportString(info: any): string | undefined {
121
+ // AST 优先:兼容 Literal 与无表达式的 TemplateLiteral
122
+ const ast: any = info.ast
123
+ try {
124
+ if (ast && Array.isArray(ast.body)) {
125
+ for (const node of ast.body) {
126
+ if (node.type === 'ExportDefaultDeclaration') {
127
+ const decl = node.declaration
128
+ if (decl?.type === 'Literal' && typeof decl.value === 'string') {
129
+ return decl.value
130
+ }
131
+ if (decl?.type === 'TemplateLiteral' && (decl.expressions?.length ?? 0) === 0) {
132
+ return decl.quasis?.[0]?.value?.cooked
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ catch (_) {
139
+ // 忽略 AST 解析异常,走回退
140
+ }
141
+ // 正则回退:兼容 ' " ` 三种引号与空白
142
+ const m = info.code?.match(/export\s+default\s+(['"`])([\s\S]*?)\1/)
143
+ return m?.[2]
144
+ }
145
+
120
146
  export function patchTabsPlugin() {
121
147
  return createPatchPlugin({
122
148
  name: '@sugarat/theme-plugin-patch-tabs',
@@ -243,8 +269,9 @@ export function coverImgTransform() {
243
269
  if (!relativePathMap[info.id]) {
244
270
  return
245
271
  }
246
- const asset = info.code?.match(/export default "(.*)"/)?.[1]
272
+ const asset = extractDefaultExportString(info)
247
273
  if (!asset) {
274
+ console.warn(`[coverImgTransform] 解析默认导出失败: ${info.id}`)
248
275
  return
249
276
  }
250
277