Astro Theme Pure

Back

内容展示

关于内容页面渲染

Shiki 代码#

您可以在配置文件 astro.config.ts 中的 defineConfig.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%'> <!-- [!code ++] -->
            本文最后更新已超过一年,部分信息可能已过时。 <!-- [!code ++] -->
          </p> 
        ) 
      } 
    </Fragment>
  </Hero>
astro

它将渲染如下:

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