短代码

作者:Goose 和 Quill
8 分钟阅读 901 字

目录

  1. 如何使用
  2. 1. Alert
  3. 2. ImageCode
  4. 3. Video
  5. 4. Youtube
  6. 5. Bilibili
  7. 6. Spotify
  8. 7. Steam
  9. 8. CRT
  10. 实用建议

目前可用的短代码:

如何使用

在 MDX 中,这些组件已经通过 ExtendMarkdown.astro 注入,所以你可以直接这样写:

<Alert type="note">Hello</Alert>

无需额外导入。

1. Alert

渲染 GitHub 风格的提示块。

属性

属性类型默认值描述
type'note' | 'tip' | 'important' | 'warning' | 'caution''note'提示样式

示例

<Alert type="note">
这是一个提示。
</Alert>
<Alert type="warning">
这是一个警告。
</Alert>

说明

2. ImageCode

渲染一张图片,并支持一组可组合的样式类。

属性

属性类型默认值描述
urlstring原图 URL,必填
url_minstringundefined预览/压缩图片 URL;提供后显示预览图并链接到 url
altstring''替代文本
fullbooleanfalse使图片填满内容宽度
full_bleedbooleanfalse让图片超出内容栏
startbooleanfalse将图片浮动到起始侧
endbooleanfalse将图片浮动到结束侧
pixelsbooleanfalse使用像素艺术风格渲染
transparentbooleanfalse更适合透明图片
no_hoverbooleanfalse禁用悬停缩放
spoilerbooleanfalse应用剧透遮罩
solidbooleanfalse更强的剧透遮罩,与 spoiler 配合使用

示例

<ImageCode
url="/images/example.png"
alt="示例图片"
no_hover="true"
/>
<ImageCode
url="/images/original.png"
url_min="/images/preview.png"
alt="可点击的预览"
full="true"
/>

说明

3. Video

渲染本地或远程视频,支持与 ImageCode 大多数相同的展示类。

属性

属性类型默认值描述
urlstring视频 URL,必填
altstring''用作 aria-label 的无障碍文本
fullbooleanfalse填满内容宽度
full_bleedbooleanfalse更宽的展示
startbooleanfalse浮动到起始侧
endbooleanfalse浮动到结束侧
pixelsbooleanfalse像素艺术渲染风格
transparentbooleanfalse透明展示风格
spoilerbooleanfalse剧透遮罩
solidbooleanfalsespoiler 配合使用时的更强遮罩
autoplaybooleanfalse自动播放视频
controlsbooleanfalse显示原生控件
loopbooleanfalse循环播放
mutedbooleanfalse静音开始
playsinlinebooleanfalse请求内联播放

示例

<Video
url="/videos/demo.webm"
alt="演示视频"
controls="true"
/>
<Video
url="/videos/hero.webm"
full_bleed="true"
autoplay="true"
muted="true"
loop="true"
playsinline="true"
/>

说明

4. Youtube

使用 youtube-nocookie.com 域名嵌入 YouTube 视频。

属性

属性类型默认值描述
idstringYouTube 视频 ID,必填
autoplaybooleanfalse是否自动播放
startnumberundefined开始时间(秒)

示例

<Youtube id="0Da8ZhKcNKQ" />
<Youtube id="0Da8ZhKcNKQ" autoplay="true" start={30} />

说明

5. Bilibili

嵌入 Bilibili 播放器。

属性

属性类型默认值描述
bvidstringundefinedBV ID
aidstringundefinedAV ID
cidstringundefined资源/弹幕 ID
pagenumber1分P编号
autoplaybooleanfalse是否自动播放

示例

<Bilibili bvid="BV1yt4y1Q7SS" />
<Bilibili
bvid="BV1yt4y1Q7SS"
page={2}
autoplay="true"
/>

说明

6. Spotify

嵌入 Spotify 内容,如专辑、播放列表、曲目、节目和剧集。

属性

属性类型默认值描述
type'track' | 'album' | 'artist' | 'playlist' | 'episode' | 'show'undefined通用类型表单
idstringundefinedtype 配合使用的 content ID
trackstringundefined曲目 ID 简写
albumstringundefined专辑 ID 简写
artiststringundefined艺术家 ID 简写
playliststringundefined播放列表 ID 简写
episodestringundefined剧集 ID 简写
showstringundefined节目 ID 简写
heightstring | numberauto自定义 iframe 高度

示例

<Spotify album="5gDJVilnZpPt8zwBC467UH" />
<Spotify type="track" id="11dFghVXANMlKmJXsNCbNl" />
<Spotify playlist="37i9dQZF1DXcBWIGoYBM5M" height={480} />

说明

7. Steam

显示 Steam 商店卡片。

属性

属性类型默认值描述
appidstring | numberSteam App ID,必填
variant'horizontal' | 'vertical''horizontal'卡片布局

示例

<Steam appid="1127400" />
<Steam appid="730" variant="vertical" />

说明

8. CRT

渲染 CRT 风格的代码容器。

属性

属性类型默认值描述
codestring要显示的代码文本,必填
no_scanlinesbooleanfalse禁用扫描线效果

示例

<CRT code={`
Hello, CRT
`} />
<CRT
no_scanlines="true"
code={`
No scanlines here
`}
/>

说明

实用建议

媒体

嵌入

提示和展示


关系图谱

Loading graph...