Skip to content

Commit 5be26cc

Browse files
committed
feat: 🚀 新增主题模式和主题尺寸的默认值配置
1 parent ba5ffc6 commit 5be26cc

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
## TODO
66

7-
- 首页 PostList 图片支持单选数镜像对称,镜像对称参考 `http://niubin.site/`
87
- 添加评论功能
98
- 文章页支持动态全屏大小和默认大小
109
- 归档页添加 commit 图标风格,如:`http://niubin.site/archive.html`

vitepress-theme-tk/src/components/RightBottomButton.vue

+13-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ onUnmounted(() => {
3030
});
3131
3232
const { theme } = useUnrefData();
33-
const { themeMode = [], themeSize = [] } = theme;
33+
const { themeMode = "vp-default", themeModeAppend = [], themeSize = "default", themeSizeAppend = [] } = theme;
3434
3535
// 主题切换
3636
const showThemeModeItem = ref(false);
37-
const currentThemeMode = ref("vp-default");
37+
const currentThemeMode = ref(themeMode);
3838
3939
const themeModeList = [
4040
{
@@ -57,29 +57,37 @@ const themeModeList = [
5757
{ name: "红色", theme: "el-red" },
5858
],
5959
},
60-
...themeMode,
60+
...themeModeAppend,
6161
];
6262
6363
const changeThemeMode = (themeMode: string) => {
64+
if (themeMode === unref(currentThemeMode)) return;
6465
currentThemeMode.value = themeMode;
6566
document.documentElement.setAttribute("theme", themeMode);
6667
};
6768
69+
// 初始化主题模式
70+
changeThemeMode(themeMode);
71+
6872
// 主题尺寸
6973
const showThemeSizeItem = ref(false);
70-
const currentThemeSize = ref("default");
74+
const currentThemeSize = ref(themeSize);
7175
7276
const themeSizeList = [
7377
{ name: "Large", size: "large" },
7478
{ name: "Default", size: "default" },
7579
{ name: "Small", size: "small" },
76-
...themeSize,
80+
...themeSizeAppend,
7781
];
7882
7983
const changeThemeSize = (themeSize: string) => {
84+
if (themeSize === unref(currentThemeSize)) return;
8085
currentThemeSize.value = themeSize;
8186
document.documentElement.setAttribute("size", themeSize);
8287
};
88+
89+
// 初始化主题尺寸
90+
changeThemeSize(themeSize);
8391
</script>
8492

8593
<template>

vitepress-theme-tk/src/config/types.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,23 @@ export interface KtThemeConfig {
7676
showCapture?: boolean;
7777
};
7878
/**
79-
* 主题模式配置
79+
* 设置当前主题模式
80+
* @default 'vp-default'
8081
*/
81-
themeMode?: {
82+
themeMode?:
83+
| "vp-default"
84+
| "vp-green"
85+
| "vp-yellow"
86+
| "vp-red"
87+
| "el-blue"
88+
| "el-green"
89+
| "el-yellow"
90+
| "el-red"
91+
| string;
92+
/**
93+
* 自定义主题模式,将会追加到内置主题模式后面
94+
*/
95+
themeModeAppend?: {
8296
/**
8397
* 主题组名称
8498
*/
@@ -101,10 +115,11 @@ export interface KtThemeConfig {
101115
theme: string;
102116
}[];
103117
}[];
118+
themeSize?: "small" | "default" | "large" | string;
104119
/**
105-
* 主题尺寸配置
120+
* 自定义主题尺寸,将会追加到内置主题尺寸后面
106121
*/
107-
themeSize?: {
122+
themeSizeAppend?: {
108123
/**
109124
* 主题尺寸名称,用于页面文字渲染
110125
*/

0 commit comments

Comments
 (0)