-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
308 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<script setup lang="ts"> | ||
import { version } from "~/package.json" | ||
import { DateUtil } from "zhi-common" | ||
import { useI18n } from "vue-i18n" | ||
import { useBaseUrl } from "~/plugins/renderer/useClientBaseUrl" | ||
import { useStaticThemeMode } from "~/composables/useStaticThemeMode" | ||
// uses | ||
const { t } = useI18n() | ||
const { colorMode, toggleDark } = await useStaticThemeMode() | ||
const { getHome } = useBaseUrl() | ||
// datas | ||
const v = ref(version) | ||
const nowYear = DateUtil.nowYear() | ||
// methods | ||
const goGithub = () => { | ||
window.open("https://github.com/terwer/siyuan-plugin-blog") | ||
} | ||
const goAbout = () => { | ||
window.open("https://blog.terwer.space/about") | ||
} | ||
// methods | ||
const goHome = async () => { | ||
const home = getHome() | ||
window.open(home) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="footer"> | ||
<div> | ||
<span class="text"> ©2011-{{ nowYear }} </span> | ||
<span class="text s-dark" @click="goGithub()"> siyuan-plugin-blog </span> | ||
|
||
<span class="text">v{{ v }} </span> | ||
|
||
<span class="text s-dark" @click="goHome()">{{ t("go.home") }}</span> | ||
|
||
<span class="text">.</span> | ||
<span class="text s-dark" @click="goAbout()">{{ t("syp.about") }}</span> | ||
|
||
<span class="text">.</span> | ||
<span class="text s-dark" @click="toggleDark()">{{ | ||
colorMode ? t("theme.mode.light") : t("theme.mode.dark") | ||
}}</span> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.footer { | ||
font-size: 12px; | ||
color: #bbb; | ||
text-align: center; | ||
padding-bottom: 8px; | ||
} | ||
.footer .text { | ||
vertical-align: middle; | ||
} | ||
.s-dark { | ||
color: var(--el-color-primary); | ||
cursor: pointer; | ||
} | ||
</style> |
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,7 @@ | ||
<script setup lang="ts"></script> | ||
|
||
<template> | ||
<header></header> | ||
</template> | ||
|
||
<style scoped></style> |
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,134 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import { BrowserUtil } from "zhi-device" | ||
import { createAppLogger } from "~/common/appLogger" | ||
|
||
// 创建日志记录器 | ||
const logger = createAppLogger("use-theme-mode") | ||
|
||
export const useStaticThemeMode = async () => { | ||
// 获取颜色模式和运行时配置 | ||
const color = useColorMode() | ||
const env = useRuntimeConfig() | ||
const appBase = process.env.APP_BASE | ||
|
||
// computes | ||
// 获取颜色模式并暴露 computed 属性 | ||
const colorMode = computed({ | ||
get: () => { | ||
return color.value === "dark" | ||
}, | ||
set: (value) => { | ||
color.value = value ? "dark" : "light" | ||
}, | ||
}) | ||
|
||
// methods | ||
// 切换暗黑模式 | ||
const toggleDark = async () => { | ||
colorMode.value = !colorMode.value | ||
switchMode() | ||
} | ||
|
||
// 在 mounted 生命周期中处理加载后逻辑 | ||
// onMounted(() => { | ||
// }) | ||
|
||
const siyuanV = "2.9.1" | ||
const hljsV = "11.5.0" | ||
const siyuanLightTheme = "Zhihu" | ||
const siyuanDarkTheme = "Zhihu" | ||
const siyuanThemeV = "0.0.7" | ||
const detectedMode = color.preference | ||
const isDarkMode = detectedMode === "dark" | ||
useHead({ | ||
htmlAttrs: { | ||
lang: "zh_CN", | ||
"data-theme-mode": detectedMode, | ||
"data-light-theme": siyuanLightTheme, | ||
"data-dark-theme": siyuanDarkTheme, | ||
}, | ||
link: [ | ||
{ | ||
rel: "stylesheet", | ||
id: "themeDefaultStyle", | ||
href: `${appBase}resources/appearance/themes/${isDarkMode ? "midnight" : "daylight"}/theme.css?v=${siyuanV}`, | ||
}, | ||
{ | ||
rel: "stylesheet", | ||
id: "themeStyle", | ||
href: `${appBase}resources/appearance/themes/${ | ||
isDarkMode ? siyuanDarkTheme : siyuanLightTheme | ||
}/theme.css?v=${siyuanThemeV}`, | ||
}, | ||
{ | ||
rel: "stylesheet", | ||
id: "protyleHljsStyle", | ||
href: `${appBase}resources/stage/protyle/js/highlight.js/styles/vs${ | ||
isDarkMode ? "2015" : "" | ||
}.min.css?v=${hljsV}`, | ||
}, | ||
], | ||
}) | ||
|
||
// ================================================== | ||
// private methods | ||
// ================================================== | ||
const switchMode = () => { | ||
const isDarkMode = color.value === "dark" | ||
setThemeMode(isDarkMode) | ||
} | ||
|
||
// 设置主题模式 | ||
const setThemeMode = (isDarkMode: boolean) => { | ||
if (BrowserUtil.isInBrowser) { | ||
setCssAndThemeMode(isDarkMode) | ||
// 记录日志 | ||
logger.debug(isDarkMode ? "Browser Dark Mode" : "Browser Light Mode") | ||
logger.info(`Auto set mode, isDark => ${isDarkMode}`) | ||
} | ||
|
||
color.preference = isDarkMode ? "dark" : "light" | ||
} | ||
|
||
// 根据浏览器模式设置 CSS 和主题模式 | ||
const setCssAndThemeMode = (isDarkMode: boolean) => { | ||
// 默认主题适配 | ||
const themeDefaultStyle = document.querySelector("#themeDefaultStyle") as any | ||
themeDefaultStyle.href = | ||
appBase + `resources/appearance/themes/${isDarkMode ? "midnight" : "daylight"}/theme.css?v=${siyuanV}` | ||
|
||
// 代码块适配 | ||
const protyleHljsStyle = document.querySelector("#protyleHljsStyle") as any | ||
protyleHljsStyle.href = | ||
appBase + `resources/stage/protyle/js/highlight.js/styles/vs${isDarkMode ? "2015" : ""}.min.css?v=${hljsV}` | ||
|
||
// 颜色模式属性 | ||
document.documentElement.dataset.themeMode = isDarkMode ? "dark" : "light" | ||
} | ||
|
||
return { colorMode, toggleDark } | ||
} |
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
Oops, something went wrong.