Fix: theme local options

This commit is contained in:
JimhHan 2021-04-07 22:20:50 +08:00
parent 5d09bc4d76
commit f1671b156f
No known key found for this signature in database
GPG Key ID: 48D5D7CF95157AC5
6 changed files with 16 additions and 18 deletions

View File

@ -23,7 +23,6 @@ export default defineUserConfig<DefaultThemeOptions>({
editLinks: true, editLinks: true,
editLinkText: "帮助我们改善此页面!", editLinkText: "帮助我们改善此页面!",
enableToggle: true, enableToggle: true,
ToggleText: "切换主题",
navbar: [ navbar: [
{ text: "首页", link: "/" }, { text: "首页", link: "/" },
{ text: "大史记", link: "/about/news.md" }, { text: "大史记", link: "/about/news.md" },
@ -159,6 +158,11 @@ export default defineUserConfig<DefaultThemeOptions>({
themePlugins: { themePlugins: {
git: process.env.NODE_ENV === "production", git: process.env.NODE_ENV === "production",
}, },
locales: {
"/": {
ToggleText: "切换主题",
},
},
}, },
markdown: { markdown: {
toc: { toc: {

View File

@ -10,8 +10,8 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from "vue"; import { defineComponent } from "vue";
import { ThemeOptions } from "../index"; import { useThemeLocaleData } from "@vuepress/plugin-theme-data/lib/composables";
declare const __LAYOUT__OPTIONS__: ThemeOptions; import { ToggleOptions } from "../types";
export default defineComponent({ export default defineComponent({
data() { data() {
@ -21,8 +21,9 @@ export default defineComponent({
}; };
}, },
mounted() { mounted() {
this.enable = __LAYOUT__OPTIONS__.enableToggle; const option = useThemeLocaleData<ToggleOptions>();
this.text = __LAYOUT__OPTIONS__.ToggleText; this.enable = option.value.enableToggle;
this.text = option.value.ToggleText;
}, },
methods: { methods: {
toggleTheme() { toggleTheme() {

View File

@ -1,21 +1,13 @@
import { path } from "@vuepress/utils"; import { path } from "@vuepress/utils";
import { Theme } from "@vuepress/core"; import { Theme } from "@vuepress/core";
export interface ThemeOptions { export const docsPlugin: Theme = (options, app) => {
enableToggle?: boolean;
ToggleText?: string;
}
export const docsPlugin: Theme<ThemeOptions> = (options, app) => {
return { return {
name: "xray-docs-theme", name: "xray-docs-theme",
extends: "@vuepress/theme-default", extends: "@vuepress/theme-default",
layouts: { layouts: {
Layout: path.resolve(__dirname, "layouts/Layout.vue"), Layout: path.resolve(__dirname, "layouts/Layout.vue"),
}, },
define: {
__LAYOUT__OPTIONS__: options,
},
clientAppEnhanceFiles: path.resolve(__dirname, "clientAppEnhance.ts"), clientAppEnhanceFiles: path.resolve(__dirname, "clientAppEnhance.ts"),
plugins: [["@vuepress/plugin-palette", { preset: "sass" }]], plugins: [["@vuepress/plugin-palette", { preset: "sass" }]],
}; };

View File

@ -29,7 +29,3 @@ export default defineComponent({
}, },
}); });
</script> </script>
<style lang="sass">
//@import "../styles/default/index.scss"
</style>

View File

@ -0,0 +1 @@
export * from "./toggle";

View File

@ -0,0 +1,4 @@
export interface ToggleOptions {
enableToggle?: boolean;
ToggleText?: string;
}