旁注
要与页面的主要内容一起显示次要信息,请使用 <Aside>
组件。
import { Aside } from '@astrojs/starlight/components';
使用 <Aside>
组件显示一个旁注(也称为“admonitions”或“callouts”)。
一个 <Aside>
可以有一个可选的 type
属性,它控制旁注的颜色、图标和默认标题。
import { Aside } from '@astrojs/starlight/components';
<Aside>Some content in an aside.</Aside>
<Aside type="caution">Some cautionary content.</Aside>
<Aside type="tip">
Other content is also supported in asides.
```js// A code snippet, for example.```
</Aside>
<Aside type="danger">Do not give your password to anyone.</Aside>
{% aside %}Some content in an aside.{% /aside %}
{% aside type="caution" %}Some cautionary content.{% /aside %}
{% aside type="tip" %}Other content is also supported in asides.
```js// A code snippet, for example.```{% /aside %}
{% aside type="danger" %}Do not give your password to anyone.{% /aside %}
Starlight 还提供了一种自定义语法,用于在 Markdown 和 MDX 中渲染旁注,作为 <Aside>
组件的替代方案。有关自定义语法的详细信息,请参阅“在 Markdown 中编写内容”指南。
使用自定义标题
标题为“使用自定义标题”的部分通过使用 title
属性来覆盖默认的旁注标题。
import { Aside } from '@astrojs/starlight/components';
<Aside type="caution" title="Watch out!"> A warning aside *with* a custom title.</Aside>
{% aside type="caution" title="Watch out!" %}A warning aside *with* a custom title.{% /aside %}
使用自定义图标
标题为“使用自定义图标”的部分通过将 icon
属性设置为 Starlight 的一个内置图标的名称来覆盖默认的旁注图标。
import { Aside } from '@astrojs/starlight/components';
<Aside type="tip" icon="starlight"> A tip aside *with* a custom icon.</Aside>
{% aside type="tip" icon="starlight" %}A tip aside *with* a custom icon.{% /aside %}
<Aside>
属性
标题为“<Aside> 属性”的部分实现: Aside.astro
<Aside>
组件接受以下属性
type
标题为“type”的部分type: 'note' | 'tip' | 'caution' | 'danger'
默认值: 'note'
要显示的旁注类型
note
类型的旁注(默认)是蓝色的,并显示一个信息图标。tip
类型的旁注是紫色的,并显示一个火箭图标。caution
类型的旁注是黄色的,并显示一个三角形的警告图标。danger
类型的旁注是红色的,并显示一个八角形的警告图标。
title
标题为“title”的部分类型: string
要显示的旁注标题。如果未设置 title
,将使用当前旁注 type
的默认标题。
icon
标题为“icon”的部分type: StarlightIcon
旁注可以包含一个 icon
属性,设置为 Starlight 的一个内置图标的名称。