-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(CopyrightInfo): 修复显示bug * feat(nav): 添加导航栏切换字体功能 * style: 优化 css 内的字体导入方式 * style: 更新 css 引入链接,添加新字体 * Update src/plugins/fontSwitcher.js Co-authored-by: Estela ad Astra <[email protected]> Signed-off-by: Lee <[email protected]> --------- Signed-off-by: Lee <[email protected]> Co-authored-by: Estela ad Astra <[email protected]>
- Loading branch information
Showing
6 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
export const fontMap = { | ||
// 字体映射表 | ||
'霞鹜文楷': 'LXGW WenKai', | ||
'霞鹜文楷 Mono': 'LXGW WenKai Mono', | ||
'霞鹜新晰黑': 'LXGW Neo XiHei', | ||
'新晰黑 Code': 'NeoXiHei Code', | ||
'系统字体': 'system-ui', | ||
'更纱黑体': 'Sarasa UI CL', | ||
'思源宋体': 'Source Han Serif CN', | ||
'黑体': 'sans', | ||
'宋体': 'serif', | ||
}; | ||
|
||
// 字体切换函数 | ||
export const switchFont = (font) => { | ||
document.documentElement.style.setProperty('--main-font', fontMap[font]); | ||
}; | ||
|
||
// 添加全局字体切换事件监听 | ||
export const addFontSwitchListener = () => { | ||
// 选择汉堡菜单 | ||
const hamburger = document.querySelector('.VPNavBarHamburger'); | ||
const fontSwitchItems = document.querySelectorAll('.items a'); // 选择所有导航项的 a 标签 | ||
// console.log(`找到 ${fontSwitchItems.length} 个字体切换项`); | ||
|
||
fontSwitchItems.forEach(item => { | ||
item.addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
const target = e.target; | ||
const selectedFont = target.innerText; // 获取点击的字体名称 | ||
// console.log(`${selectedFont}`); | ||
switchFont(selectedFont); // 切换字体 | ||
}); | ||
}); | ||
|
||
// 添加汉堡菜单事件监听 | ||
if (hamburger) { | ||
hamburger.addEventListener('click', () => { | ||
// 在汉堡菜单打开时添加字体切换事件监听 | ||
const fontSwitchItems = document.querySelectorAll('.items a'); // 选择所有导航项的 a 标签 | ||
// console.log(`找到 ${fontSwitchItems.length} 个字体切换项`); | ||
|
||
fontSwitchItems.forEach(item => { | ||
item.addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
const target = e.target; | ||
const selectedFont = target.innerText; // 获取点击的字体名称 | ||
// console.log(`${selectedFont}`); | ||
switchFont(selectedFont); // 切换字体 | ||
}); | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import 'https://fonts.project-trans.org/fonts.css'; | ||
:root { | ||
--vp-font-family-base: var(--main-font, system-ui) !important;/* 文本字体 */ | ||
--vp-font-family-mono: var(--main-font, system-ui) !important;/* 代码字体 */ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters