@sugarat/theme 0.5.16 → 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.d.ts +3 -11
- package/node.js +50 -9
- package/node.mjs +50 -9
- package/package.json +8 -5
- package/src/components/BlogApp.vue +0 -10
- package/src/composables/config/index.ts +3 -12
- package/src/utils/node/theme.ts +8 -8
- package/src/utils/node/vitePlugins.ts +57 -1
package/node.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DefaultTheme, UserConfig } from 'vitepress';
|
|
2
|
+
import { BackToTopPluginOptions } from 'vitepress-plugin-back2top';
|
|
2
3
|
import { RSSOptions } from 'vitepress-plugin-rss';
|
|
3
4
|
import { Repo, Mapping } from '@giscus/vue';
|
|
4
5
|
import { Options } from 'oh-my-live2d';
|
|
@@ -106,6 +107,7 @@ declare namespace Theme {
|
|
|
106
107
|
inputPosition?: 'top' | 'bottom';
|
|
107
108
|
lang?: string;
|
|
108
109
|
loading?: 'lazy' | 'eager';
|
|
110
|
+
showCommentBtn?: boolean;
|
|
109
111
|
}
|
|
110
112
|
interface ArtalkOption {
|
|
111
113
|
site: string;
|
|
@@ -498,17 +500,7 @@ declare namespace Theme {
|
|
|
498
500
|
*/
|
|
499
501
|
weeksAgo?: string;
|
|
500
502
|
} | ((date: Date | string) => string);
|
|
501
|
-
interface BackToTop {
|
|
502
|
-
/**
|
|
503
|
-
* 距离顶部多少距离出现
|
|
504
|
-
* @default 450
|
|
505
|
-
*/
|
|
506
|
-
top?: number;
|
|
507
|
-
/**
|
|
508
|
-
* 设置展示图标,svg
|
|
509
|
-
* @recommend https://iconbuddy.app/search?q=fire
|
|
510
|
-
*/
|
|
511
|
-
icon?: string;
|
|
503
|
+
interface BackToTop extends BackToTopPluginOptions {
|
|
512
504
|
}
|
|
513
505
|
interface TaskCheckbox {
|
|
514
506
|
disabled?: boolean;
|
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.
|
|
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;
|
|
@@ -463,13 +463,6 @@ async function getArticles(cfg, vpConfig) {
|
|
|
463
463
|
}
|
|
464
464
|
function patchVPConfig(vpConfig, cfg) {
|
|
465
465
|
vpConfig.head = vpConfig.head || [];
|
|
466
|
-
if (cfg?.comment && "type" in cfg.comment && cfg?.comment?.type === "artalk") {
|
|
467
|
-
const server = cfg.comment?.options?.server;
|
|
468
|
-
if (server) {
|
|
469
|
-
vpConfig.head.push(["link", { href: `${server} /dist/Artalk.css`, rel: "stylesheet" }]);
|
|
470
|
-
vpConfig.head.push(["script", { src: `${server} /dist/Artalk.js`, id: "artalk-script" }]);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
466
|
}
|
|
474
467
|
function patchVPThemeConfig(cfg, vpThemeConfig = {}) {
|
|
475
468
|
vpThemeConfig.sidebar = patchDefaultThemeSideBar(cfg)?.sidebar;
|
|
@@ -487,6 +480,9 @@ var import_vitepress_plugin_pagefind = require("vitepress-plugin-pagefind");
|
|
|
487
480
|
var import_vitepress_plugin_rss = require("vitepress-plugin-rss");
|
|
488
481
|
var import_theme_shared4 = require("@sugarat/theme-shared");
|
|
489
482
|
var import_vitepress_plugin_announcement = require("vitepress-plugin-announcement");
|
|
483
|
+
var import_vitepress_plugin_artalk = require("vitepress-plugin-artalk");
|
|
484
|
+
var import_vitepress_plugin_back2top = require("vitepress-plugin-back2top");
|
|
485
|
+
var import_vitepress_plugin_giscus = require("vitepress-plugin-giscus");
|
|
490
486
|
var import_vitepress_plugin_group_icons2 = require("vitepress-plugin-group-icons");
|
|
491
487
|
var import_vitepress_plugin_image_preview = require("vitepress-plugin-image-preview");
|
|
492
488
|
|
|
@@ -595,6 +591,25 @@ function getVitePlugins(cfg = {}) {
|
|
|
595
591
|
;
|
|
596
592
|
[cfg?.RSS].flat().forEach((rssConfig) => plugins.push((0, import_vitepress_plugin_rss.RssPlugin)(rssConfig)));
|
|
597
593
|
}
|
|
594
|
+
if (cfg?.comment && typeof cfg.comment !== "boolean") {
|
|
595
|
+
const commentConfig = cfg.comment;
|
|
596
|
+
const isArtalk = commentConfig.type === "artalk";
|
|
597
|
+
if (isArtalk) {
|
|
598
|
+
plugins.push((0, import_vitepress_plugin_artalk.artalkPlugin)(commentConfig.options));
|
|
599
|
+
}
|
|
600
|
+
const isGiscus = commentConfig.type === "giscus" || commentConfig.repo;
|
|
601
|
+
if (isGiscus) {
|
|
602
|
+
const { mobileMinify, label, icon } = commentConfig;
|
|
603
|
+
const options = {
|
|
604
|
+
...commentConfig.options,
|
|
605
|
+
...commentConfig,
|
|
606
|
+
mobileMinify,
|
|
607
|
+
label,
|
|
608
|
+
icon
|
|
609
|
+
};
|
|
610
|
+
plugins.push((0, import_vitepress_plugin_giscus.giscusPlugin)(options));
|
|
611
|
+
}
|
|
612
|
+
}
|
|
598
613
|
if (cfg?.popover) {
|
|
599
614
|
plugins.push((0, import_vitepress_plugin_announcement.AnnouncementPlugin)(cfg.popover));
|
|
600
615
|
}
|
|
@@ -608,6 +623,10 @@ function getVitePlugins(cfg = {}) {
|
|
|
608
623
|
if (cfg?.timeline !== false) {
|
|
609
624
|
plugins.push(patchTimelinePlugin());
|
|
610
625
|
}
|
|
626
|
+
if (cfg?.backToTop !== false) {
|
|
627
|
+
const options = typeof cfg.backToTop === "object" ? cfg.backToTop : {};
|
|
628
|
+
plugins.push((0, import_vitepress_plugin_back2top.back2topPlugin)(options));
|
|
629
|
+
}
|
|
611
630
|
return plugins;
|
|
612
631
|
}
|
|
613
632
|
function patchGroupIconPlugin() {
|
|
@@ -618,6 +637,27 @@ function patchGroupIconPlugin() {
|
|
|
618
637
|
}
|
|
619
638
|
});
|
|
620
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
|
+
}
|
|
621
661
|
function patchTabsPlugin() {
|
|
622
662
|
return createPatchPlugin({
|
|
623
663
|
name: "@sugarat/theme-plugin-patch-tabs",
|
|
@@ -703,8 +743,9 @@ function coverImgTransform() {
|
|
|
703
743
|
if (!relativePathMap[info.id]) {
|
|
704
744
|
return;
|
|
705
745
|
}
|
|
706
|
-
const asset = info
|
|
746
|
+
const asset = extractDefaultExportString(info);
|
|
707
747
|
if (!asset) {
|
|
748
|
+
console.warn(`[coverImgTransform] \u89E3\u6790\u9ED8\u8BA4\u5BFC\u51FA\u5931\u8D25: ${info.id}`);
|
|
708
749
|
return;
|
|
709
750
|
}
|
|
710
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.
|
|
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;
|
|
@@ -430,13 +430,6 @@ async function getArticles(cfg, vpConfig) {
|
|
|
430
430
|
}
|
|
431
431
|
function patchVPConfig(vpConfig, cfg) {
|
|
432
432
|
vpConfig.head = vpConfig.head || [];
|
|
433
|
-
if (cfg?.comment && "type" in cfg.comment && cfg?.comment?.type === "artalk") {
|
|
434
|
-
const server = cfg.comment?.options?.server;
|
|
435
|
-
if (server) {
|
|
436
|
-
vpConfig.head.push(["link", { href: `${server} /dist/Artalk.css`, rel: "stylesheet" }]);
|
|
437
|
-
vpConfig.head.push(["script", { src: `${server} /dist/Artalk.js`, id: "artalk-script" }]);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
433
|
}
|
|
441
434
|
function patchVPThemeConfig(cfg, vpThemeConfig = {}) {
|
|
442
435
|
vpThemeConfig.sidebar = patchDefaultThemeSideBar(cfg)?.sidebar;
|
|
@@ -456,6 +449,9 @@ import {
|
|
|
456
449
|
import { RssPlugin } from "vitepress-plugin-rss";
|
|
457
450
|
import { cacheAllGitTimestamps, joinPath as joinPath2 } from "@sugarat/theme-shared";
|
|
458
451
|
import { AnnouncementPlugin } from "vitepress-plugin-announcement";
|
|
452
|
+
import { artalkPlugin } from "vitepress-plugin-artalk";
|
|
453
|
+
import { back2topPlugin } from "vitepress-plugin-back2top";
|
|
454
|
+
import { giscusPlugin } from "vitepress-plugin-giscus";
|
|
459
455
|
import { groupIconVitePlugin } from "vitepress-plugin-group-icons";
|
|
460
456
|
import { ImagePreviewPlugin } from "vitepress-plugin-image-preview";
|
|
461
457
|
|
|
@@ -564,6 +560,25 @@ function getVitePlugins(cfg = {}) {
|
|
|
564
560
|
;
|
|
565
561
|
[cfg?.RSS].flat().forEach((rssConfig) => plugins.push(RssPlugin(rssConfig)));
|
|
566
562
|
}
|
|
563
|
+
if (cfg?.comment && typeof cfg.comment !== "boolean") {
|
|
564
|
+
const commentConfig = cfg.comment;
|
|
565
|
+
const isArtalk = commentConfig.type === "artalk";
|
|
566
|
+
if (isArtalk) {
|
|
567
|
+
plugins.push(artalkPlugin(commentConfig.options));
|
|
568
|
+
}
|
|
569
|
+
const isGiscus = commentConfig.type === "giscus" || commentConfig.repo;
|
|
570
|
+
if (isGiscus) {
|
|
571
|
+
const { mobileMinify, label, icon } = commentConfig;
|
|
572
|
+
const options = {
|
|
573
|
+
...commentConfig.options,
|
|
574
|
+
...commentConfig,
|
|
575
|
+
mobileMinify,
|
|
576
|
+
label,
|
|
577
|
+
icon
|
|
578
|
+
};
|
|
579
|
+
plugins.push(giscusPlugin(options));
|
|
580
|
+
}
|
|
581
|
+
}
|
|
567
582
|
if (cfg?.popover) {
|
|
568
583
|
plugins.push(AnnouncementPlugin(cfg.popover));
|
|
569
584
|
}
|
|
@@ -577,6 +592,10 @@ function getVitePlugins(cfg = {}) {
|
|
|
577
592
|
if (cfg?.timeline !== false) {
|
|
578
593
|
plugins.push(patchTimelinePlugin());
|
|
579
594
|
}
|
|
595
|
+
if (cfg?.backToTop !== false) {
|
|
596
|
+
const options = typeof cfg.backToTop === "object" ? cfg.backToTop : {};
|
|
597
|
+
plugins.push(back2topPlugin(options));
|
|
598
|
+
}
|
|
580
599
|
return plugins;
|
|
581
600
|
}
|
|
582
601
|
function patchGroupIconPlugin() {
|
|
@@ -587,6 +606,27 @@ function patchGroupIconPlugin() {
|
|
|
587
606
|
}
|
|
588
607
|
});
|
|
589
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
|
+
}
|
|
590
630
|
function patchTabsPlugin() {
|
|
591
631
|
return createPatchPlugin({
|
|
592
632
|
name: "@sugarat/theme-plugin-patch-tabs",
|
|
@@ -672,8 +712,9 @@ function coverImgTransform() {
|
|
|
672
712
|
if (!relativePathMap[info.id]) {
|
|
673
713
|
return;
|
|
674
714
|
}
|
|
675
|
-
const asset = info
|
|
715
|
+
const asset = extractDefaultExportString(info);
|
|
676
716
|
if (!asset) {
|
|
717
|
+
console.warn(`[coverImgTransform] \u89E3\u6790\u9ED8\u8BA4\u5BFC\u51FA\u5931\u8D25: ${info.id}`);
|
|
677
718
|
return;
|
|
678
719
|
}
|
|
679
720
|
viteAssetsMap[info.id] = asset;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarat/theme",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.18",
|
|
4
4
|
"description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
|
|
5
5
|
"author": "sugar",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,10 +52,13 @@
|
|
|
52
52
|
"vitepress-plugin-mermaid": "2.0.13",
|
|
53
53
|
"vitepress-plugin-tabs": "0.7.3",
|
|
54
54
|
"@sugarat/theme-shared": "0.0.7",
|
|
55
|
-
"vitepress-plugin-
|
|
55
|
+
"vitepress-plugin-back2top": "0.1.0",
|
|
56
|
+
"vitepress-plugin-announcement": "0.1.7",
|
|
57
|
+
"vitepress-plugin-giscus": "0.1.0",
|
|
58
|
+
"vitepress-plugin-artalk": "0.1.0",
|
|
59
|
+
"vitepress-plugin-image-preview": "0.1.2",
|
|
56
60
|
"vitepress-plugin-rss": "0.4.3",
|
|
57
|
-
"vitepress-plugin-pagefind": "0.4.19"
|
|
58
|
-
"vitepress-plugin-announcement": "0.1.7"
|
|
61
|
+
"vitepress-plugin-pagefind": "0.4.19"
|
|
59
62
|
},
|
|
60
63
|
"devDependencies": {
|
|
61
64
|
"artalk": "^2.8.5",
|
|
@@ -63,7 +66,7 @@
|
|
|
63
66
|
"pagefind": "^1.3.0",
|
|
64
67
|
"typescript": "^5.4.5",
|
|
65
68
|
"vite": "^5.4.9",
|
|
66
|
-
"vitepress": "2.0.0-alpha.
|
|
69
|
+
"vitepress": "2.0.0-alpha.17",
|
|
67
70
|
"vue": "^3.5.24",
|
|
68
71
|
"vitepress-plugin-51la": "0.1.1"
|
|
69
72
|
},
|
|
@@ -13,13 +13,8 @@ import BlogArticleAnalyze from './BlogArticleAnalyze.vue'
|
|
|
13
13
|
import BlogAlert from './BlogAlert.vue'
|
|
14
14
|
import BlogFooter from './BlogFooter.vue'
|
|
15
15
|
import BlogHomeHeaderAvatar from './BlogHomeHeaderAvatar.vue'
|
|
16
|
-
import BlogBackToTop from './BlogBackToTop.vue'
|
|
17
|
-
import CommentGiscus from './CommentGiscus.vue'
|
|
18
16
|
import BlogOml2d from './BlogOml2d.vue'
|
|
19
|
-
|
|
20
|
-
import CommentArtalk from './CommentArtalk.vue'
|
|
21
17
|
import BlogButtonAfterArticle from './BlogButtonAfterArticle.vue'
|
|
22
|
-
import BlogCommentWrapper from './BlogCommentWrapper.vue'
|
|
23
18
|
|
|
24
19
|
const { frontmatter } = useData()
|
|
25
20
|
const layout = computed(() => frontmatter.value.layout)
|
|
@@ -86,11 +81,6 @@ const openTransition = useDarkTransitionConfig()
|
|
|
86
81
|
<!-- 评论 -->
|
|
87
82
|
<ClientOnly>
|
|
88
83
|
<BlogButtonAfterArticle />
|
|
89
|
-
<BlogBackToTop />
|
|
90
|
-
<BlogCommentWrapper>
|
|
91
|
-
<CommentArtalk />
|
|
92
|
-
<CommentGiscus />
|
|
93
|
-
</BlogCommentWrapper>
|
|
94
84
|
</ClientOnly>
|
|
95
85
|
</template>
|
|
96
86
|
<template #layout-bottom>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable ts/no-namespace */
|
|
2
2
|
import type { DefaultTheme } from 'vitepress'
|
|
3
|
+
import type { BackToTopPluginOptions } from 'vitepress-plugin-back2top'
|
|
3
4
|
import type { RSSOptions } from 'vitepress-plugin-rss'
|
|
4
5
|
import type { Mapping, Repo } from '@giscus/vue'
|
|
5
6
|
import type { Options as Oml2dOptions } from 'oh-my-live2d'
|
|
@@ -109,6 +110,7 @@ export namespace Theme {
|
|
|
109
110
|
inputPosition?: 'top' | 'bottom'
|
|
110
111
|
lang?: string
|
|
111
112
|
loading?: 'lazy' | 'eager'
|
|
113
|
+
showCommentBtn?: boolean
|
|
112
114
|
}
|
|
113
115
|
export interface ArtalkOption {
|
|
114
116
|
site: string
|
|
@@ -528,18 +530,7 @@ export namespace Theme {
|
|
|
528
530
|
*/
|
|
529
531
|
weeksAgo?: string
|
|
530
532
|
} | ((date: Date | string) => string)
|
|
531
|
-
export interface BackToTop {
|
|
532
|
-
/**
|
|
533
|
-
* 距离顶部多少距离出现
|
|
534
|
-
* @default 450
|
|
535
|
-
*/
|
|
536
|
-
top?: number
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* 设置展示图标,svg
|
|
540
|
-
* @recommend https://iconbuddy.app/search?q=fire
|
|
541
|
-
*/
|
|
542
|
-
icon?: string
|
|
533
|
+
export interface BackToTop extends BackToTopPluginOptions {
|
|
543
534
|
}
|
|
544
535
|
|
|
545
536
|
export interface TaskCheckbox {
|
package/src/utils/node/theme.ts
CHANGED
|
@@ -128,14 +128,14 @@ export async function getArticles(cfg: Partial<Theme.BlogConfig>, vpConfig: Site
|
|
|
128
128
|
|
|
129
129
|
export function patchVPConfig(vpConfig: any, cfg?: Partial<Theme.BlogConfig>) {
|
|
130
130
|
vpConfig.head = vpConfig.head || []
|
|
131
|
-
// Artalk 资源地址
|
|
132
|
-
if (cfg?.comment && 'type' in cfg.comment && cfg?.comment?.type === 'artalk') {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
131
|
+
// // Artalk 资源地址
|
|
132
|
+
// if (cfg?.comment && 'type' in cfg.comment && cfg?.comment?.type === 'artalk') {
|
|
133
|
+
// const server = cfg.comment?.options?.server
|
|
134
|
+
// if (server) {
|
|
135
|
+
// vpConfig.head.push(['link', { href: `${server}/dist/Artalk.css`, rel: 'stylesheet' }])
|
|
136
|
+
// vpConfig.head.push(['script', { src: `${server}/dist/Artalk.js`, id: 'artalk-script' }])
|
|
137
|
+
// }
|
|
138
|
+
// }
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
export function patchVPThemeConfig(
|
|
@@ -6,6 +6,9 @@ import { RssPlugin } from 'vitepress-plugin-rss'
|
|
|
6
6
|
import type { PluginOption } from 'vite'
|
|
7
7
|
import { cacheAllGitTimestamps, joinPath } from '@sugarat/theme-shared'
|
|
8
8
|
import { AnnouncementPlugin } from 'vitepress-plugin-announcement'
|
|
9
|
+
import { artalkPlugin } from 'vitepress-plugin-artalk'
|
|
10
|
+
import { back2topPlugin } from 'vitepress-plugin-back2top'
|
|
11
|
+
import { giscusPlugin } from 'vitepress-plugin-giscus'
|
|
9
12
|
import { groupIconVitePlugin } from 'vitepress-plugin-group-icons'
|
|
10
13
|
import { ImagePreviewPlugin } from 'vitepress-plugin-image-preview'
|
|
11
14
|
import type { Theme } from '../../composables/config/index'
|
|
@@ -56,6 +59,27 @@ export function getVitePlugins(cfg: Partial<Theme.BlogConfig> = {}) {
|
|
|
56
59
|
;[cfg?.RSS].flat().forEach(rssConfig => plugins.push(RssPlugin(rssConfig)))
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
// 内置支持 giscus 评论
|
|
63
|
+
if (cfg?.comment && typeof cfg.comment !== 'boolean') {
|
|
64
|
+
const commentConfig = cfg.comment
|
|
65
|
+
const isArtalk = (commentConfig as any).type === 'artalk'
|
|
66
|
+
if (isArtalk) {
|
|
67
|
+
plugins.push(artalkPlugin((commentConfig as any).options))
|
|
68
|
+
}
|
|
69
|
+
const isGiscus = (commentConfig as any).type === 'giscus' || (commentConfig as any).repo
|
|
70
|
+
if (isGiscus) {
|
|
71
|
+
const { mobileMinify, label, icon } = commentConfig
|
|
72
|
+
const options = {
|
|
73
|
+
...(commentConfig as any).options,
|
|
74
|
+
...commentConfig,
|
|
75
|
+
mobileMinify,
|
|
76
|
+
label,
|
|
77
|
+
icon
|
|
78
|
+
}
|
|
79
|
+
plugins.push(giscusPlugin(options))
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
59
83
|
// 内置支持 全局公告
|
|
60
84
|
if (cfg?.popover) {
|
|
61
85
|
plugins.push(AnnouncementPlugin(cfg.popover))
|
|
@@ -76,6 +100,11 @@ export function getVitePlugins(cfg: Partial<Theme.BlogConfig> = {}) {
|
|
|
76
100
|
if (cfg?.timeline !== false) {
|
|
77
101
|
plugins.push(patchTimelinePlugin())
|
|
78
102
|
}
|
|
103
|
+
// 内置支持 back-to-top
|
|
104
|
+
if (cfg?.backToTop !== false) {
|
|
105
|
+
const options = typeof cfg.backToTop === 'object' ? cfg.backToTop : {}
|
|
106
|
+
plugins.push(back2topPlugin(options))
|
|
107
|
+
}
|
|
79
108
|
return plugins
|
|
80
109
|
}
|
|
81
110
|
|
|
@@ -88,6 +117,32 @@ export function patchGroupIconPlugin() {
|
|
|
88
117
|
})
|
|
89
118
|
}
|
|
90
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
|
+
|
|
91
146
|
export function patchTabsPlugin() {
|
|
92
147
|
return createPatchPlugin({
|
|
93
148
|
name: '@sugarat/theme-plugin-patch-tabs',
|
|
@@ -214,8 +269,9 @@ export function coverImgTransform() {
|
|
|
214
269
|
if (!relativePathMap[info.id]) {
|
|
215
270
|
return
|
|
216
271
|
}
|
|
217
|
-
const asset = info
|
|
272
|
+
const asset = extractDefaultExportString(info)
|
|
218
273
|
if (!asset) {
|
|
274
|
+
console.warn(`[coverImgTransform] 解析默认导出失败: ${info.id}`)
|
|
219
275
|
return
|
|
220
276
|
}
|
|
221
277
|
|