替换主题组件
当在 行为选项 中设置 { custom: true } 时,主题将通过 @theme-hope 别名来引入组件,所以你可以利用这一点来替换主题的任何一个组件。
如何通过别名替换组件
你需要在自己的 VuePress 配置文件通过 alias 替换主题中使用的组件别名。
import { getDirname, path } from "vuepress/utils";
import { hopeTheme } from "vuepress-theme-hope";
const __dirname = getDirname(import.meta.url);
export default {
theme: hopeTheme(
{
// 主题选项
// ...
},
{ custom: true },
),
alias: {
// 你可以在这里将别名定向到自己的组件
// 比如这里我们将主题的主页组件改为用户 .vuepress/components 下的 HomePage.vue
"@theme-hope/components/home/HomePage": path.resolve(
__dirname,
"./components/HomePage.vue",
),
},
};有些组件提供了插槽,在这种情况下,你可以在覆盖组件时直接引入原组件,并通过插槽传入你需要的内容。
主题别名
基础组件
@theme-hope/components/base/AutoLink: 基础链接插槽:
default,before,after@theme-hope/components/base/BreadCrumb: 面包屑导航@theme-hope/components/base/EditIcon: 编辑图标@theme-hope/components/base/MainFadeInUpTransition: 主布局过渡插槽:
default@theme-hope/components/base/MainLayout: 主布局插槽:
default,navScreenTop,navScreenBottom,sidebarItems,sidebarTop,sidebarBottomnavScreenTopnavScreenBottom插槽被传递到NavBar组件。sidebarItems,sidebarTop,sidebarBottom插槽被传递到Sidebar组件。
@theme-hope/components/base/MarkdownContent: Markdown 内容插槽:
contentBefore,contentAfter@theme-hope/components/base/PageContent: 主要页面内容插槽:
pageTop,pageBottom,content,contentBefore,contentAfter,toc,tocBefore,tocAftercontentBefore,contentAfter插槽被传递到MarkdownContent组件。toc,tocBefore,tocAfter插槽被传递到TOC组件。
@theme-hope/components/base/PageFooter: 页脚@theme-hope/components/base/PrintButton: 打印按钮@theme-hope/components/base/PageNav: 页面导航@theme-hope/components/base/PageTitle: 页面标题@theme-hope/components/base/SkipLink: 指向主要内容的链接@theme-hope/components/base/TOC: 页面目录插槽:
toctocBefore,tocAfter
主页组件
@theme-hope/components/home/FeatureSection: 主页特色部分@theme-hope/components/home/HighlightSection: 主页高亮部分@theme-hope/components/home/HeroInfo: 主页英雄信息插槽:
heroInfo,heroLogo,heroBgheroInfo插槽接收texttaglineisFullScreen和style属性。heroLogo插槽接收imageimageDarkalt和style属性。heroBg插槽接收imageimageDark和style属性。
@theme-hope/components/home/HeroSlideDownButton: 主页英雄滑动按钮@theme-hope/components/home/HomePage: 默认主页 (项目主页)插槽:
heroInfo,heroLogo,heroBg,heroBefore,heroAfter,content,contentBefore,contentAfterheroInfo,heroLogo,heroBg插槽被传递到HeroInfo组件。heroBefore,heroAfter插槽被传递到MainFadeInUpTransition组件。
@theme-hope/components/home/PortfolioHero: 作品集英雄信息插槽:
portfolioInfo,portfolioAvatar,portfolioBgportfolioInfo插槽接收namewelcometitletitles和links属性。portfolioAvatar插槽接收avataravatarDarkstyle和alt属性。portfolioBg插槽接收imageimageDark和style属性。
@theme-hope/components/home/PortfolioHome: 作品集主页插槽:
portfolioInfo,portfolioAvatar,portfolioBgportfolioInfo,portfolioAvatar,portfolioBg插槽被传递到PortfolioHero组件。
导航栏组件
@theme-hope/components/navbar/I18nIcon: 多语言图标@theme-hope/components/navbar/LanguageDropdown: 语言下拉菜单@theme-hope/components/navbar/Navbar: 导航栏组件插槽:
navScreenTop,navScreenBottomnavScreenTopnavScreenBottom插槽被传递到NavBar组件。
@theme-hope/components/navbar/NavbarBrand: 导航栏品牌信息@theme-hope/components/navbar/NavbarDropdown: 下拉列表插槽:
title@theme-hope/components/navbar/NavbarLinks: 导航栏链接@theme-hope/components/navbar/NavScreen: 移动视图导航页面插槽:
navScreenTop,navScreenBottom@theme-hope/components/navbar/NavScreenLinks: 导航页面链接@theme-hope/components/navbar/NavScreenMenu: 导航页面菜单@theme-hope/components/navbar/RepoLink: 仓库链接@theme-hope/components/navbar/ToggleNavbarButton: 导航栏切换按钮@theme-hope/components/navbar/ToggleSidebarButton: 侧边栏切换按钮
侧边栏组件
@theme-hope/components/sidebar/Sidebar: 侧边栏插槽:
sidebarItems,sidebarTop,sidebarBottomsidebarItems插槽接收sidebarItems属性。
@theme-hope/components/sidebar/SidebarChild: 侧边栏子项@theme-hope/components/sidebar/SidebarGroup: 侧边栏组@theme-hope/components/sidebar/SidebarLinks: 侧边栏链接
信息组件
@theme-hope/components/info/AuthorInfo: 作者信息@theme-hope/components/info/CategoryInfo: 分类信息@theme-hope/components/info/DateInfo: 日期信息@theme-hope/components/info/OriginalInfo: 原创标记@theme-hope/components/info/PageInfo: 页面信息@theme-hope/components/info/PageMeta: 页面元信息@theme-hope/components/info/PageViewInfo: 页面浏览量信息@theme-hope/components/info/ReadingTimeInfo: 阅读时间信息@theme-hope/components/info/TagInfo: 标签信息@theme-hope/components/info/WordInfo: 字数信息@theme-hope/components/info/icons: 信息图标
外观组件
@theme-hope/components/appearance/AppearanceButton: 外观按钮@theme-hope/components/appearance/AppearanceIcon: 外观图标@theme-hope/components/appearance/AppearanceSettings: 外观设置@theme-hope/components/appearance/ColorMode: 颜色模式@theme-hope/components/appearance/ColorModeSwitch: 颜色模式开关@theme-hope/components/appearance/ThemeColor: 主题颜色@theme-hope/components/appearance/ThemeColorPicker: 主题颜色选择器@theme-hope/components/appearance/ToggleFullScreen: 全屏切换@theme-hope/components/appearance/ToggleFullScreenButton: 全屏切换按钮
过渡组件
@theme-hope/components/transition/DropTransition: 下落过渡组件
插槽:default
博客组件
@theme-hope/components/blog/ArticleItem: 文章项目插槽:
articleTitle,articleCover,articleInfo,articleExcerptarticleTitle插槽接收titleisEncrypted和type属性。articleCover插槽接收cover属性。articleInfo插槽接收authorcategorytagdateisOriginalpageviewreadingTime和readingTimeLocale属性。articleExcerpt插槽接收excerpt属性。
@theme-hope/components/blog/ArticleList: 文章列表插槽:
articleTitle,articleCover,articleInfo,articleExcerptarticleTitle,articleCover,articleInfo,articleExcerpt插槽被传递到ArticleItem组件。
@theme-hope/components/blog/ArticlesInfo: 文章信息@theme-hope/components/blog/ArticleType: 文章类型@theme-hope/components/blog/BloggerInfo: 博主信息插槽:
bloggerInfobloggerInfo插槽接收nameavatar和description属性。
@theme-hope/components/blog/BlogHero: 博客英雄信息插槽:
heroInfo,heroLogo,heroBgheroInfo插槽接收texttaglineisFullScreen和style属性。heroLogo插槽接收imageimageDarkalt和style属性。heroBg插槽接收imageimageDark和style属性。
@theme-hope/components/blog/BlogHome: 博客主页插槽:
heroInfo,heroLogo,heroBg,heroBefore,heroAfter,articleCover,articleTitle,articleInfo,articleExcerpt,bloggerInfo,infoBefore,infoAfter,content,contentBefore,contentAfterheroInfo,heroLogo,heroBg插槽被传递到BlogHero组件。articleTitle,articleCover,articleInfo,articleExcerpt插槽被传递到ArticleList组件。bloggerInfo插槽被传递到BloggerInfo组件。infoBefore,infoAfter插槽被传递到InfoPanel组件。contentBefore,contentAfter插槽被传递到MarkdownContent组件。
@theme-hope/components/blog/BlogMainLayout: 博客主布局插槽:
default,navScreenTop,navScreenBottom,sidebarItems,sidebarTop,sidebarBottom,bloggerInfonavScreenTopnavScreenBottom插槽被传递到NavBar组件。
@theme-hope/components/blog/CategoriesInfo: 分类信息@theme-hope/components/blog/CategoryList: 分类列表@theme-hope/components/blog/CategoryPage: 分类页面插槽:
default,articleTitle,articleCover,articleInfo,articleExcerpt,articleBefore,articleAfter,bloggerInfo,infoBefore,infoAfterarticleTitle,articleCover,articleInfo,articleExcerpt插槽被传递到ArticleList组件。bloggerInfo插槽被传递到BloggerInfo组件。infoBefore,infoAfter插槽被传递到InfoPanel组件。
@theme-hope/components/blog/InfoList: 信息列表插槽:
bloggerInfo,infoBefore,infoAfter@theme-hope/components/blog/InfoPanel: 信息面板bloggerInfo插槽被传递到BloggerInfo组件。
@theme-hope/components/blog/Pagination: 分页导航@theme-hope/components/blog/ProjectPanel: 博客项目面板@theme-hope/components/blog/SocialMedias: 社交媒体链接@theme-hope/components/blog/TagList: 标签列表@theme-hope/components/blog/TagPage: 标签页面@theme-hope/components/blog/TagsInfo: 标签信息@theme-hope/components/blog/TimelineItems: 时间线项目@theme-hope/components/blog/TimelineList: 时间线列表@theme-hope/components/blog/TimelinePage: 时间线页面插槽:
articleBefore,articleAfter,bloggerInfo,infoBefore,infoAfterbloggerInfo插槽被传递到BloggerInfo组件。infoBefore,infoAfter插槽被传递到InfoPanel组件。
@theme-hope/components/blog/TypePage: type page插槽:
default,articleTitle,articleCover,articleInfo,articleExcerpt,articleBefore,articleAfter,bloggerInfo,infoBefore,infoAfterarticleTitle,articleCover,articleInfo,articleExcerpt插槽被传递到ArticleList组件。bloggerInfo插槽被传递到BloggerInfo组件。infoBefore,infoAfter插槽被传递到InfoPanel组件。
@theme-hope/components/blog/icons: 博客图标
加密组件
@theme-hope/modules/encrypt/components/GlobalEncrypt: 全局加密插槽:
default@theme-hope/modules/encrypt/components/LocalEncrypt: 局部加密插槽:
default@theme-hope/modules/encrypt/components/PasswordModal: 密码输入
其他别名
主题的可组合式 API,布局和工具函数也提供了别名。详见 主题源代码。
更新日志
05fbb-于1e9f5-于98fc7-于329ae-于f3e43-于b1230-于f7910-于edfd5-于f565a-于2c32a-于6ad69-于9ff54-于e788a-于6c081-于95ac5-于3360a-于f9d00-于54c46-于05f91-于2f38e-于794f9-于31bea-于d7e50-于c2e16-于fa8bb-于39704-于a0afc-于f314f-于92fc8-于21d14-于9a137-于f1436-于96e01-于885a2-于74d2f-于bade3-于8174c-于a0c8a-于aafa6-于42b11-于3f76b-于c4fe2-于79ac6-于8e2fc-于13530-于ad675-于4659f-于2fa50-于393ff-于23515-于9cdd7-于63d09-于ad023-于7f1ab-于22000-于fd395-于73de5-于fc15c-于da2ed-于21000-于bcf02-于716f9-于f6ff0-于95ff3-于37324-于