首页
VitePress默认主题提供了首页布局,您也可以在本站首页上看到使用的布局。您可以通过在 frontmatter 中指定 layout: home
在任何页面上使用它。
yaml
---
layout: home
---
然而,仅此选项并没有多大作用。您可以通过设置其他选项(例如hero
和features
)向首页添加多个不同的预模板"部分"。
Hero 部分
Hero 部分位于首页顶部。以下是配置 Hero 部分的方法。
yaml
---
layout: home
hero:
name: VitePress
text: Vite & Vue powered static site generator.
tagline: Lorem ipsum...
image:
src: /logo.png
alt: VitePress
actions:
- theme: brand
text: Get Started
link: /guide/what-is-vitepress
- theme: alt
text: View on GitHub
link: https://github.com/vuejs/vitepress
---
ts
interface Hero {
// The string shown top of `text`. Comes with brand color
// and expected to be short, such as product name.
name?: string
// The main text for the hero section. This will be defined
// as `h1` tag.
text: string
// Tagline displayed below `text`.
tagline?: string
// The image is displayed next to the text and tagline area.
image?: ThemeableImage
// Action buttons to display in home hero section.
actions?: HeroAction[]
}
type ThemeableImage =
| string
| { src: string; alt?: string }
| { light: string; dark: string; alt?: string }
interface HeroAction {
// Color theme of the button. Defaults to `brand`.
theme?: 'brand' | 'alt'
// Label of the button.
text: string
// Destination link of the button.
link: string
}
自定义名称颜色
VitePress 使用品牌颜色(--vp-c-brand
)作为name
。但是,您可以通过覆盖 --vp-home-hero-name-color
变量来自定义此颜色。
css
:root {
--vp-home-hero-name-color: blue;
}
您还可以通过组合--vp-home-hero-name-background
来进一步自定义它,以提供name
渐变颜色。
css
:root {
--vp-home-hero-name-color: transparent;
--vp-home-hero-name-background: -webkit-linear-gradient(120deg, #bd34fe, #41d1ff);
}
Features 部分
在features
部分中,您可以在hero
部分之后列出您想要显示的任意数量的功能。要配置它,请将features
选项传递给 frontmatter。
您可以为每个功能提供一个图标,可以是表情符号或任何类型的图像。当配置的图标是图像(svg、png、jpeg...)时,您必须为图标提供适当的宽度和高度;您还可以在需要时提供描述、其内在大小以及深色和浅色主题的变体。
yaml
---
layout: home
features:
- icon: 🛠️
title: Simple and minimal, always
details: Lorem ipsum...
- icon:
src: /cool-feature-icon.svg
title: Another cool feature
details: Lorem ipsum...
- icon:
dark: /dark-feature-icon.svg
light: /light-feature-icon.svg
title: Another cool feature
details: Lorem ipsum...
---
ts
interface Feature {
// Show icon on each feature box.
icon?: FeatureIcon
// Title of the feature.
title: string
// Details of the feature.
details: string
// Link when clicked on feature component. The link can
// be both internal or external.
//
// e.g. `guid/reference/default-theme-home-page` or `htttps://example.com`
link?: string
// Link text to be shown inside feature component. Best
// used with `link` option.
//
// e.g. `Learn more`, `Visit page`, etc.
linkText?: string
// Link rel attribute for the `link` option.
//
// e.g. `external`
rel?: string
}
type FeatureIcon =
| string
| { src: string; alt?: string; width?: string; height: string }
| {
light: string
dark: string
alt?: string
width?: string
height: string
}