Astro Narrow 主题配置指南

Astro Narrow 主题配置指南

介绍 Astro Narrow 的站点配置、内容类型、Markdown 能力和项目链接配置。

Astro Narrow 是 Narrow 阅读体验的 Astro-native 实现。它使用内容集合、类型化配置、Astro 组件和构建期 Markdown 转换,不保留 Hugo 兼容层。

配置 site.ts#

src/config/site.ts 控制站点信息、导航、整体宽度、评论、统计、图库和文章设置。

配置用途
name, shortName, description站点元信息
author首页个人信息卡片和社交链接
contentWidth主体布局宽度
ui.navbar.sticky是否固定导航栏
ui.dock.enabled是否显示底部 dock
nav顶部导航
footerNav底部导航
commentsGiscus 配置
analyticsUmami 配置
gallery, lightboxMarkdown 图片行为
post.relatedCount相关文章数量
post.license版权许可区块
export const siteConfig = {
name: 'Astro Narrow',
shortName: 'Narrow',
description: '一个内容优先的 Astro 主题。',
contentWidth: '56rem'
}

配置内容类型#

src/config/content.ts 定义每种内容在导航、列表、卡片和首页中的展示方式。

配置可选值
cardStylearticle, showcase, compact
listLayoutstack, grid
gridColumns1, 2, 3
home.enabled是否在首页展示
home.limit首页展示数量
home.featuredOnly仅展示 featured 内容
src/config/content.ts
export const contentTypes = {
posts: {
collection: 'posts',
path: '/posts/',
label: { en: 'Posts', 'zh-cn': '文章' },
cardStyle: 'article',
listLayout: 'stack',
gridColumns: 1
}
}

Frontmatter#

文章使用 Astro content collections。建议保持 frontmatter 简洁稳定。

字段用途
title页面标题
description摘要和 meta description
pubDate发布日期
updatedDate可选更新日期
cover封面图
tags标签分类
toccenter, side, true, false
comments单篇评论开关
math, mermaid, gallery, lightbox功能提示

项目内容还支持 featuredlinks

links:
- label: Website
url: https://example.com
icon: lucide:external-link
- label: GitHub
url: https://github.com/example/repo
icon: simple-icons:github
featured: true

Markdown 能力#

Note

尽量使用 Markdown 原生输入。Astro Narrow 通过 remark 和 rehype 转换常见结构。

功能输入方式
提示块GitHub 风格引用块
Tabs::::tabs:::tab{title="..."}
图库连续书写 Markdown 图片
数学公式$x^2$$$...$$
Mermaidmermaid 代码块
代码块Expressive Code

代码#

theme.ts
type ColorMode = 'light' | 'dark' | 'auto';
export function setMode(mode: ColorMode) {
document.documentElement.classList.toggle('dark', mode === 'dark');
}

图库#

数学和 Mermaid#

行内公式:E=mc2E = mc^2

flowchart LR A[Markdown] --> B[remark/rehype] B --> C[Astro 组件] C --> D[静态站点]
版权许可

CC BY-NC-SA 4.0 许可协议。