Skip to content

Commit 0056bbb

Browse files
committed
fix: 🐞 theme 支持响应式
1 parent f8fd50b commit 0056bbb

File tree

30 files changed

+122
-139
lines changed

30 files changed

+122
-139
lines changed

build/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const updateVersionInTs = async () => {
5050

5151
const versionFile = resolve(tkRoot, "src/version.ts");
5252
const versionContent = await readFile(versionFile, "utf-8");
53-
const newVersion = versionContent.replace("1.0.0", tkPackageInfo.version);
53+
const newVersion = versionContent.replace(/"([^"]+)"/, `"${tkPackageInfo.version}"`);
5454

5555
await writeFile(versionFile, newVersion);
5656
};

vitepress-theme-teek/src/components/ArticleAnalyze/src/index.vue

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useRoute, useData } from "vitepress";
44
import { Reading, Clock, View } from "@element-plus/icons-vue";
55
import { FileInfo } from "vitepress-plugin-doc-analysis";
66
import { useNamespace, useBuSunZi, type UseBuSunZi } from "../../../hooks";
7-
import { useUnrefData } from "../../../configProvider";
87
import ArticleBreadcrumb from "../../ArticleBreadcrumb";
98
import ArticleInfo from "../../ArticleInfo";
109
import Icon from "../../Icon";
@@ -15,19 +14,18 @@ defineOptions({ name: "ArticleAnalyze" });
1514
1615
const ns = useNamespace("articleAnalyze");
1716
18-
const { theme } = useUnrefData();
19-
const { theme: themeRef, frontmatter } = useData();
17+
const { theme, frontmatter } = useData();
2018
2119
// 文章基本信息
2220
const post = computed<TkContentData>(() => ({
23-
author: { ...theme.author, ...unref(frontmatter).author },
21+
author: { ...unref(theme).author, ...unref(frontmatter).author },
2422
date: unref(frontmatter).date,
2523
frontmatter: unref(frontmatter),
2624
url: "",
2725
}));
2826
2927
// 站点信息数据
30-
const docAnalysisInfo = computed(() => unref(themeRef).docAnalysisInfo || {});
28+
const docAnalysisInfo = computed(() => unref(theme).docAnalysisInfo || {});
3129
3230
// 文章阅读量、阅读时长、字数
3331
const pageViewInfo = computed(() => {
@@ -41,7 +39,11 @@ const pageViewInfo = computed(() => {
4139
4240
// 文章信息配置项
4341
const articleConfig = computed<Article>(() => {
44-
const { showInfo = true, showIcon = true, teleport = {} } = { ...theme.article, ...unref(frontmatter).article };
42+
const {
43+
showInfo = true,
44+
showIcon = true,
45+
teleport = {},
46+
} = { ...unref(theme).article, ...unref(frontmatter).article };
4547
return { showInfo, showIcon, teleport };
4648
});
4749
@@ -79,7 +81,7 @@ const docAnalysisConfig = computed<DocAnalysis>(() => {
7981
wordCount = true,
8082
readingTime = true,
8183
statistics = {},
82-
}: DocAnalysis = { ...theme.docAnalysis, ...unref(frontmatter).docAnalysis };
84+
}: DocAnalysis = { ...unref(theme).docAnalysis, ...unref(frontmatter).docAnalysis };
8385
8486
return { wordCount, readingTime, statistics };
8587
});

vitepress-theme-teek/src/components/ArticleBreadcrumb/src/index.vue

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import { useNamespace } from "../../../hooks";
66
import Breadcrumb from "./Breadcrumb.vue";
77
import BreadcrumbItem from "./BreadcrumbItem.vue";
88
import Icon from "../../Icon";
9-
import { useUnrefData } from "../../../configProvider";
109
import { Breadcrumb as BreadcrumbType } from "../../../config/types";
1110
1211
defineOptions({ name: "ArticleBreadcrumb" });
1312
1413
const ns = useNamespace("articleBreadcrumb");
1514
16-
const { theme } = useUnrefData();
17-
const { localeIndex, frontmatter, page } = useData();
15+
const { localeIndex, theme, frontmatter, page } = useData();
1816
1917
// 面包屑配置项
2018
const breadcrumb = computed<BreadcrumbType>(() => ({
2119
enabled: true,
2220
showCurrentName: false,
2321
separator: "/",
24-
...theme.breadcrumb,
22+
...unref(theme).breadcrumb,
2523
...unref(frontmatter).breadcrumb,
2624
}));
2725
@@ -42,7 +40,7 @@ const breadcrumbList = computed(() => {
4240
) {
4341
classifyList.push({
4442
fileName,
45-
filePath: theme.catalogues?.inv[item]?.filePath || "",
43+
filePath: unref(theme).catalogues?.inv[item]?.filePath || "",
4644
});
4745
}
4846
});

vitepress-theme-teek/src/components/ArticleInfo/src/index.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { User, Calendar, FolderOpened, CollectionTag, EditPen } from "@element-plus/icons-vue";
33
import { useRoute, withBase, useData } from "vitepress";
44
import { computed, unref } from "vue";
5-
import { usePosts, useUnrefData } from "../../../configProvider";
5+
import { usePosts } from "../../../configProvider";
66
import { formatDate, isFunction } from "../../../helper";
77
import { TkContentData } from "../../../post/types";
88
import { useNamespace } from "../../../hooks";
@@ -16,8 +16,7 @@ const ns = useNamespace("articleInfo");
1616
1717
const { post, scope, split = false } = defineProps<PostBaseInfoProps>();
1818
19-
const { theme } = useUnrefData();
20-
const { frontmatter, page } = useData();
19+
const { theme, frontmatter, page } = useData();
2120
// 文章信息配置项
2221
const articleConfig = computed<Article>(() => {
2322
const {
@@ -29,7 +28,7 @@ const articleConfig = computed<Article>(() => {
2928
showCategory = false,
3029
showTag = false,
3130
}: Article = {
32-
...theme.article,
31+
...unref(theme).article,
3332
...unref(frontmatter).article,
3433
...unref(frontmatter).tk?.article,
3534
};

vitepress-theme-teek/src/components/BodyBgImage/src/index.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<script setup lang="ts" name="BodyBgImage">
22
import { onMounted, unref } from "vue";
3+
import { withBase, useData } from "vitepress";
34
import { useNamespace, useSwitchData } from "../../../hooks";
4-
import { useUnrefData } from "../../../configProvider";
55
import { isString } from "../../../helper";
66
import { BodyBgImg } from "../../../config/types";
7-
import { withBase } from "vitepress";
87
98
defineOptions({ name: "BodyBgImage" });
109
1110
const ns = useNamespace("bodyBgImage");
1211
13-
const { theme } = useUnrefData();
12+
const { theme } = useData();
1413
1514
let {
1615
imgSrc,
@@ -19,7 +18,7 @@ let {
1918
imgShuffle = false,
2019
mask = false,
2120
maskBg = "rgba(0, 0, 0, 0.2)",
22-
}: BodyBgImg = theme.bodyBgImg || {};
21+
}: BodyBgImg = unref(theme).bodyBgImg || {};
2322
2423
// body 背景图片定时轮播
2524
const { data: imageSrc, startAutoSwitch: switchImg } = useSwitchData({

vitepress-theme-teek/src/components/CommentArtalk/src/index.vue

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts" name="CommentArtalk">
22
import { inject, onMounted, onUnmounted, ref, unref, watch } from "vue";
33
import { useData } from "vitepress";
4-
import { useUnrefData } from "../../../configProvider";
54
import { CommentProvider } from "../../../config/types";
65
import { useNamespace, useVpRouter } from "../../../hooks";
76
import { artalkSymbol } from "./artalk";
@@ -11,10 +10,9 @@ defineOptions({ name: "CommentArtalk" });
1110
const ns = useNamespace("");
1211
const vpRouter = useVpRouter();
1312
14-
const { isDark, page } = useData();
15-
const { theme } = useUnrefData();
13+
const { theme, isDark, page } = useData();
1614
17-
const { server, site }: CommentProvider["artalk"] = { ...theme.comment?.options };
15+
const { server, site }: CommentProvider["artalk"] = { ...unref(theme).comment?.options };
1816
1917
const artalkRef = ref<HTMLElement | null>(null);
2018
const artalkJs = ref<HTMLScriptElement | null>(null);
@@ -26,7 +24,7 @@ const initArtalkByInject = () => {
2624
const getArtalkInstance = inject(artalkSymbol);
2725
const el = unref(artalkRef) || `#${artalkId}`;
2826
29-
const artalkInstance = getArtalkInstance?.(theme.comment?.options, el);
27+
const artalkInstance = getArtalkInstance?.(unref(theme).comment?.options, el);
3028
3129
if (!artalkInstance) return false;
3230

vitepress-theme-teek/src/components/CommentGiscus/src/index.vue

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts" name="CommentGiscus">
22
import { ref, nextTick, onMounted, computed, unref, inject } from "vue";
33
import { useData } from "vitepress";
4-
import { useUnrefData } from "../../../configProvider";
54
import { isFunction } from "../../../helper";
65
import type { CommentProvider } from "../../../config/types";
76
import { useNamespace, useVpRouter } from "../../../hooks";
@@ -12,8 +11,7 @@ defineOptions({ name: "CommentGiscus" });
1211
const ns = useNamespace("");
1312
const vpRouter = useVpRouter();
1413
15-
const { isDark } = useData();
16-
const { theme } = useUnrefData();
14+
const { theme, isDark } = useData();
1715
1816
const {
1917
repo,
@@ -32,7 +30,7 @@ const {
3230
link = "https://giscus.app/client.js",
3331
integrity,
3432
...options
35-
}: CommentProvider["giscus"] = { ...theme.comment?.options };
33+
}: CommentProvider["giscus"] = { ...unref(theme).comment?.options };
3634
3735
const giscusTheme = computed(() => {
3836
if (isFunction(giscusThemeConfig)) return giscusThemeConfig(unref(isDark));
@@ -41,7 +39,7 @@ const giscusTheme = computed(() => {
4139
4240
// 尝试从上下文获取 giscus 组件
4341
const giscusComponentFn = inject(giscusSymbol);
44-
const giscusComponent = giscusComponentFn?.(theme.comment?.options);
42+
const giscusComponent = giscusComponentFn?.(unref(theme).comment?.options);
4543
4644
const isShow = ref(false);
4745

vitepress-theme-teek/src/components/CommentTwikoo/src/index.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts" name="CommentTwikoo">
22
import { ref, onMounted, unref } from "vue";
3-
import { useUnrefData } from "../../../configProvider";
3+
import { useData } from "vitepress";
44
import { CommentProvider } from "../../../config/types";
55
import { useNamespace, useVpRouter } from "../../../hooks";
66
@@ -9,7 +9,7 @@ defineOptions({ name: "CommentTwikoo" });
99
const ns = useNamespace("");
1010
const vpRouter = useVpRouter();
1111
12-
const { theme } = useUnrefData();
12+
const { theme } = useData();
1313
1414
const {
1515
envId,
@@ -18,7 +18,7 @@ const {
1818
katex,
1919
timeout = 700,
2020
...options
21-
}: CommentProvider["twikoo"] = { ...theme.comment?.options };
21+
}: CommentProvider["twikoo"] = { ...unref(theme).comment?.options };
2222
2323
const initTwikoo = () => {
2424
if (!envId) return;

vitepress-theme-teek/src/components/CommentWaline/src/index.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts" name="CommentWaline">
2-
import { inject, onMounted } from "vue";
3-
import { useUnrefData } from "../../../configProvider";
2+
import { inject, onMounted, unref } from "vue";
3+
import { useData } from "vitepress";
44
import { CommentProvider } from "../../../config/types";
55
import { useNamespace, useVpRouter } from "../../../hooks";
66
import { WalineInstance, walineSymbol } from "./waline";
@@ -10,7 +10,7 @@ defineOptions({ name: "CommentWaline" });
1010
const ns = useNamespace("");
1111
const vpRouter = useVpRouter();
1212
13-
const { theme } = useUnrefData();
13+
const { theme } = useData();
1414
1515
const {
1616
serverURL,
@@ -19,15 +19,15 @@ const {
1919
dark = "html[class='dark']",
2020
cssIntegrity,
2121
...options
22-
}: CommentProvider["waline"] = { ...theme.comment?.options };
22+
}: CommentProvider["waline"] = { ...unref(theme).comment?.options };
2323
2424
let waline: WalineInstance | null = null;
2525
const walineId = "waline";
2626
2727
const initWalineByInject = () => {
2828
// 尝试从上下文获取 waline 实例
2929
const getWalineInstance = inject(walineSymbol);
30-
if (getWalineInstance) waline = getWalineInstance?.(theme.comment?.options, `#${walineId}`);
30+
if (getWalineInstance) waline = getWalineInstance?.(unref(theme).comment?.options, `#${walineId}`);
3131
3232
return waline;
3333
};

vitepress-theme-teek/src/components/Footer/src/index.vue

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<script setup lang="ts" name="Footer">
2-
import { computed } from "vue";
3-
import { withBase } from "vitepress";
2+
import { computed, unref } from "vue";
3+
import { withBase, useData } from "vitepress";
44
import { useNamespace } from "../../../hooks";
5-
import { useUnrefData } from "../../../configProvider";
65
import themeSvg from "../../../assets/svg/footerTheme";
76
import copyrightSvg from "../../../assets/svg/copyright";
87
import icpRecordSvg from "../../../assets/svg/icpRecord";
@@ -16,9 +15,12 @@ defineOptions({ name: "Footer" });
1615
1716
const ns = useNamespace("footer");
1817
19-
const { theme, frontmatter } = useUnrefData();
18+
const { theme, frontmatter } = useData();
2019
21-
const { footerInfo, social = [] }: { footerInfo: FooterInfo; social: Social[] } = { ...theme, ...frontmatter.tk };
20+
const { footerInfo, social = [] }: { footerInfo: FooterInfo; social: Social[] } = {
21+
...unref(theme),
22+
...unref(frontmatter).tk,
23+
};
2224
2325
const footerData = computed(() => {
2426
const { theme = {}, copyright = {}, icpRecord, securityRecord }: FooterInfo = footerInfo || {};

vitepress-theme-teek/src/components/Home/src/index.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed, ref, unref, provide } from "vue";
33
import { useData } from "vitepress";
44
import { postDataUpdateSymbol } from "./home";
55
import { useNamespace } from "../../../hooks";
6-
import { usePage, useUnrefData } from "../../../configProvider";
6+
import { usePage } from "../../../configProvider";
77
import HomeFullscreenWallpaper from "../../HomeFullscreenWallpaper";
88
import HomeBanner from "../../HomeBanner";
99
import HomeRightInfo from "../../HomeRightInfo";
@@ -14,11 +14,10 @@ defineOptions({ name: "Home" });
1414
const ns = useNamespace("home");
1515
1616
const { isHomePage } = usePage();
17-
const { theme } = useUnrefData();
18-
const { frontmatter } = useData();
17+
const { theme, frontmatter } = useData();
1918
2019
const themeConfig = computed(() => {
21-
const { tkHome = true, banner = {}, wallpaper = {}, bodyBgImg = {} } = { ...theme, ...unref(frontmatter).tk };
20+
const { tkHome = true, banner = {}, wallpaper = {}, bodyBgImg = {} } = { ...unref(theme), ...unref(frontmatter).tk };
2221
return { tkHome, banner, wallpaper, bodyBgImg };
2322
});
2423

vitepress-theme-teek/src/components/HomeBanner/src/HomeBannerBgImage.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<script setup lang="ts" name="HomeBannerBgImage">
2-
import { withBase } from "vitepress";
2+
import { withBase, useData } from "vitepress";
33
import { onMounted, unref } from "vue";
44
import { useNamespace, useSwitchData } from "../../../hooks";
5-
import { useUnrefData } from "../../../configProvider";
65
import { isString } from "../../../helper";
76
import { Banner } from "../../../config/types";
87
98
defineOptions({ name: "HomeBannerBgImage" });
109
1110
const ns = useNamespace("bannerBgImage");
1211
13-
const { theme, frontmatter } = useUnrefData();
12+
const { theme, frontmatter } = useData();
1413
1514
// Banner 配置项
1615
const {
@@ -20,7 +19,7 @@ const {
2019
imgShuffle = false,
2120
mask = true,
2221
maskBg = "rgba(0, 0, 0, 0.4)",
23-
}: Banner = { ...theme.banner, ...frontmatter.tk?.banner };
22+
}: Banner = { ...unref(theme).banner, ...unref(frontmatter).tk?.banner };
2423
2524
// 局部图片背景风格
2625
const isPartImgBgStyle = bgStyle === "partImg";

vitepress-theme-teek/src/components/HomeBanner/src/HomeBannerBgPure.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<script setup lang="ts" name="HomeBannerBgPure">
2-
import { useUnrefData } from "../../../configProvider";
2+
import { useData } from "vitepress";
33
import { useNamespace } from "../../../hooks";
44
import { Banner } from "../../../config/types";
5+
import { unref } from "vue";
56
67
defineOptions({ name: "HomeBannerBgPure" });
78
89
const ns = useNamespace("bannerBgPure");
910
10-
const { theme, frontmatter } = useUnrefData();
11+
const { theme, frontmatter } = useData();
1112
12-
const { pureBgColor = "#28282d" }: Banner = { ...theme.banner, ...frontmatter.tk?.banner };
13+
const { pureBgColor = "#28282d" }: Banner = { ...unref(theme).banner, ...unref(frontmatter).tk?.banner };
1314
1415
const getStyle = () => {
1516
return {

0 commit comments

Comments
 (0)