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

View File

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

View File

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

View File

@ -29,7 +29,3 @@ export default defineComponent({
},
});
</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;
}