Jerry's Blog

Back

内容呈现

关于内容页面渲染

Shiki 代码#

你可以在配置文件 astro.config.tsdefineConfig.markdown.shikiConfig 中更改转换器。

基本用法#

对于 .astro 文件:

---
import { Code } from 'astro:components'
---

<Code lang='shell' code={`git log --oneline`} />
astro

对于 .mdx.md 文件:

```shell
git log --oneline
```
markdown

添加标题#

start.sh
#!/bin/bash

bun check &
bun dev
shell
```shell title="start.sh"
#!/bin/bash

bun check &
bun dev
```
markdown

显示差异#

支持添加和删除行。

deploy.sh
#!/bin/bash

bun check
bun lint
bun format
# 不需要 vercel 或其他 ci/cd
bun run build
git push
shell
```shell title="deploy.sh"
#!/bin/bash

bun check
bun lint
bun format # [!code ++]
# 不需要 vercel 或其他 ci/cd
bun run build # [!code --]
git push
```
markdown

显示高亮#

内容过期警告#

如果文章足够旧,添加一条警告信息。

src/layouts/BlogPost.astro
---
// ...
---
<Hero {data} {remarkPluginFrontmatter} slot='header'>
  <Fragment slot='description'>
    {!isDraft && enableComment && <PageInfo comment class='mt-1' />}
    {
      Math.floor((Date.now() - new Date(articleDate).getTime()) / 86400000) > 365 && (
        <p class='mt-1 text-sm italic text-primary' style='--primary:41 90% 50%'>
          本文最后更新于一年前。部分信息可能已过时。
        </p>
      )
    }
  </Fragment>
</Hero>
astro

渲染效果如下:

本文最后更新于一年前。部分信息可能已过时。