Theme Extending
vuepress-theme-hope
supports extending just like @vuepress/theme-default
.
You can create your own theme based on vuepress-theme-hope
and use it locally or publish it according to your needs.
How to Extend Theme Hope
You need to create an entry file for your theme and import hopeTheme
from vuepress-theme-hope
.
In your entry file, set extends: hopeTheme(options)
to extend the vuepress-theme-hope
theme.
The aliases of the same name (alias
) and layouts (layouts
) of your own newly created theme has higher priority over the extended theme vuepress-theme-hope
, which means that you can override vuepress-theme-hope
components via alias
option in theme api, and you can add or override layouts via layouts
in client config file.
import { getDirname, path } from "vuepress/utils";
import { hopeTheme } from "vuepress-theme-hope";
import type { ThemeOptions } from "vuepress-theme-hope";
const __dirname = getDirname(import.meta.url);
export default (options: ThemeOptions) => ({
name: "vuepress-theme-local",
extends: hopeTheme(options, { custom: true }),
alias: {
// You can override or add aliases here
// For example, here we change the vuepress-theme-hope HomePage component to components/HomePage.vue under our own theme
"@theme-hope/components/home/HomePage": path.resolve(
__dirname,
"./components/HomePage.vue",
),
},
});
import { getDirname, path } from "vuepress/utils";
import { hopeTheme } from "vuepress-theme-hope";
const __dirname = getDirname(import.meta.url);
export default (options) => ({
name: "vuepress-theme-local",
extends: hopeTheme(options, { custom: true }),
alias: {
// You can override or add aliases here
// For example, here we change the vuepress-theme-hope HomePage component to components/HomePage.vue under our own theme
"@theme-hope/components/home/HomePage": path.resolve(
__dirname,
"./components/HomePage.vue",
),
},
});
Also, you can add or override layout provided by vuepress-theme-hope
via layouts
with slots in your theme client config file.
<script setup lang="ts">
import { Layout } from "vuepress-theme-hope/client";
</script>
<template>
<Layout>
<!-- Overriding default hero logo to advanced ones, like home page of theme docs -->
<template #heroLogo>
<div>A 3D logo</div>
</template>
<!-- Introduce comment component using pageBottom slot -->
<template #pageBottom>
<CommentService />
</template>
</Layout>
</template>
<script setup lang="ts">
import { Layout } from "vuepress-theme-hope/client";
</script>
<template>
<Layout>
<!-- Adding ADs before Markdown content with contentBefore slot -->
<template #contentBefore>
<div>AD contents</div>
</template>
</Layout>
</template>
import { defineClientConfig } from "vuepress/client";
import Changelog from "./layouts/Changelog.vue";
import Home from "./layouts/Home.vue";
import Layout from "./layouts/Changelog.vue";
export default defineClientConfig({
// You can override or add layouts here
layouts: {
// a home page layout with customized hero logo
Home,
// For example, here we change the default layout of vuepress-theme-hope to layouts/Layout.vue with ADs
Layout,
// Also we added a Changelog layout
Changelog,
},
});
For details see Customize Layout with Slots.
Changelog
b546f
-on68504
-on1e9f5
-onb1230
-on54c46
-on05f91
-on8a130
-on2f38e
-ona1345
-on794f9
-onfa8bb
-on2a306
-on21d14
-on8174c
-ona0c8a
-onc4fe2
-one6b94
-on79ac6
-on5a6f8
-onad675
-on4659f
-one3f23
-on2fa50
-on23515
-on9cdd7
-on63d09
-onfd395
-on21000
-on0c093
-onf6ff0
-on95ff3
-on37324
-on