themeConfig
themeConfig
配置项作用于文章列表页、Waline 评论、自定义广告以及 AdSense 等。
示例代码
- posts - 文章列表,由 usePosts 函数生成
- page - 文章列表配置项
- max - 分页器最大页数,超出后显示首页与尾页按钮,默认为 5
- pinned - 置顶文章文本描述,默认为
[置顶]
- outDir - 文章列表、分类/归档/标签页输出路径(需与
usePosts
方法中保持一致,用于分类与标签页路由)
- comment - 评论
- ads - 自定义广告
- adsense - Google Adsense
ts
// .vitepress/config.ts
export default defineConfigWithTheme<ThemeConfig>({
themeConfig: {
posts,
page: {
max: 5,
pinned: '[置顶]'
outDir: ''
},
comment: {
serverURL: 'https://domain.com'
},
ads: {},
adsense: {}
}
});
配置项
ts
interface IPage {
max?: number;
pinned?: string;
outDir?: string;
}
interface ICommnet {
serverURL?: string;
lang?: string;
locale?: WalineLocale;
emoji?: (WalineEmojiInfo | WalineEmojiPresets)[] | false;
commentSorting?: WalineCommentSorting;
meta?: string[];
requiredMeta?: string[];
login?: string;
wordLimit?: number | [number, number];
pageSize?: number;
imageUploader?: WalineImageUploader | false;
highlighter?: WalineHighlighter | false;
texRenderer?: WalineTeXRenderer | false;
search?: WalineSearchOptions | false;
copyright?: boolean;
recaptchaV3Key?: string;
turnstileKey?: string;
reaction?: boolean | string[];
}
interface IAds {
sidebarNavBefore?: (IAd | IAd[])[];
sidebarNavAfter?: (IAd | IAd[])[];
asideOutlineBefore?: (IAd | IAd[])[];
asideOutlineAfter?: (IAd | IAd[])[];
docBefore?: (IAd | IAd[])[];
docAfter?: (IAd | IAd[])[];
}
interface IAdsense {
client?: string;
sidebarNavBefore?: string;
sidebarNavAfter?: string;
asideOutlineBefore?: string;
asideOutlineAfter?: string;
docBefore?: string;
docAfter?: string;
}
interface ThemeConfig extends DefaultTheme.Config {
posts?: IPost[];
page?: IPage;
comment?: ICommnet;
ads?: IAds;
adsense?: IAdsense;
}
预览: