-
Copyright
+
+ Copyright
+
这篇文章
- {{ `“${attrs.title}”` }}
+ {{ `“${attrs!.title}”` }}
由
{{ displayAuthors }}
{{ displayAuthors }}
@@ -79,7 +82,7 @@ watch(
许可下使用
- ,Project Trans 在
+ ,Project Trans 在
{{ attrs.copyright.license }}
{{ attrs.copyright.license }}
许可下使用
diff --git a/src/plugins/fontSwitcher.js b/src/plugins/fontSwitcher.ts
similarity index 78%
rename from src/plugins/fontSwitcher.js
rename to src/plugins/fontSwitcher.ts
index 68d16f9..4880e32 100644
--- a/src/plugins/fontSwitcher.js
+++ b/src/plugins/fontSwitcher.ts
@@ -9,10 +9,10 @@ export const fontMap = {
'思源宋体': 'Source Han Serif CN',
'黑体': 'sans',
'宋体': 'serif',
-}
+} as const
// 字体切换函数
-export function switchFont(font) {
+export function switchFont(font: keyof typeof fontMap) {
document.documentElement.style.setProperty('--main-font', fontMap[font])
}
@@ -27,9 +27,9 @@ export function addFontSwitchListener() {
item.addEventListener('click', (e) => {
e.preventDefault()
const target = e.target
- const selectedFont = target.textContent // 获取点击的字体名称
+ const selectedFont = (target as HTMLAnchorElement).textContent // 获取点击的字体名称
// console.log(`${selectedFont}`);
- switchFont(selectedFont) // 切换字体
+ switchFont(selectedFont as keyof typeof fontMap) // 切换字体
})
})
@@ -44,9 +44,9 @@ export function addFontSwitchListener() {
item.addEventListener('click', (e) => {
e.preventDefault()
const target = e.target
- const selectedFont = target.textContent // 获取点击的字体名称
+ const selectedFont = (target as HTMLAnchorElement).textContent // 获取点击的字体名称
// console.log(`${selectedFont}`);
- switchFont(selectedFont) // 切换字体
+ switchFont(selectedFont as keyof typeof fontMap) // 切换字体
})
})
})
diff --git a/src/sidebar.ts b/src/sidebar.ts
index fb996af..9117beb 100644
--- a/src/sidebar.ts
+++ b/src/sidebar.ts
@@ -8,7 +8,7 @@ import { useThemeContext } from './utils/themeContext'
export function generateSidebar() {
const { sidebarOptions } = useThemeContext()
- const optionMap: Map = new Map(sidebarOptions.map(obj => [obj.resolvePath.toString(), obj]));
+ const optionMap: Map = new Map(sidebarOptions.map(obj => [obj.resolvePath!.toString(), obj]))
const sidebar = genSidebar(sidebarOptions)
for (const key in sidebar) {
const sidebarMultiItem: SidebarMultiItem = (sidebar as any)[key]
diff --git a/src/style.css b/src/style.css
index f38daf7..1d32486 100644
--- a/src/style.css
+++ b/src/style.css
@@ -1,6 +1,5 @@
@import 'https://fonts.project-trans.org/fonts.css';
:root {
- --vp-font-family-base: var(--main-font) !important;/* 文本字体 */
- --vp-font-family-mono: var(--main-font) !important;/* 代码字体 */
+ --vp-font-family-base: var(--main-font) !important; /* 文本字体 */
+ --vp-font-family-mono: var(--main-font) !important; /* 代码字体 */
}
-
\ No newline at end of file
diff --git a/src/theme.ts b/src/theme.ts
index bba5666..e86be95 100644
--- a/src/theme.ts
+++ b/src/theme.ts
@@ -1,25 +1,25 @@
-// https://vitepress.dev/guide/custom-theme
import type { Theme } from 'vitepress'
-import DefaultTheme from 'vitepress/theme-without-fonts'
-import './style.css'
-
+import type Options from 'vitepress-sidebar'
+// https://vitepress.dev/guide/custom-theme
import {
NolebaseEnhancedReadabilitiesPlugin,
} from '@nolebase/vitepress-plugin-enhanced-readabilities/client'
+
import {
NolebaseGitChangelogPlugin,
} from '@nolebase/vitepress-plugin-git-changelog/client'
-import type Options from 'vitepress-sidebar'
+import DefaultTheme from 'vitepress/theme-without-fonts'
+import { onMounted } from 'vue'
+
+import Layout from './Layout.vue'
+import { addFontSwitchListener } from './plugins/fontSwitcher.js'
+import './style.css'
import '@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css'
+
import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
import '@nolebase/vitepress-plugin-highlight-targeted-heading/client/style.css'
-import Layout from './Layout.vue'
-
-import { onMounted } from 'vue'
-import { addFontSwitchListener } from './plugins/fontSwitcher'
-
export type SidebarOptions = Options
export default {
@@ -42,7 +42,7 @@ export default {
},
setup() {
onMounted(() => {
- addFontSwitchListener(); // 添加字体切换的事件监听器
- });
+ addFontSwitchListener() // 添加字体切换的事件监听器
+ })
},
} satisfies Theme
diff --git a/src/utils/themeContext.ts b/src/utils/themeContext.ts
index a029799..7e0cbaa 100644
--- a/src/utils/themeContext.ts
+++ b/src/utils/themeContext.ts
@@ -1,5 +1,5 @@
import type { DefaultTheme } from 'vitepress'
-import type { generateSidebar, VitePressSidebarOptions } from 'vitepress-sidebar'
+import type { VitePressSidebarOptions } from 'vitepress-sidebar'
import { AsyncLocalStorage } from 'node:async_hooks'
type NavConfig = DefaultTheme.Config['nav']