Astro Narrow Theme Guide

Astro Narrow Theme Guide

A concise guide to configuring Astro Narrow, content types, markdown features, and project links.

Astro Narrow is an Astro-native version of the Narrow reading experience. It uses content collections, typed config, Astro components, and build-time Markdown transforms instead of Hugo compatibility code.

Configure site.ts#

src/config/site.ts controls site identity, navigation, layout width, comments, analytics, gallery behavior, and post settings.

OptionPurpose
name, shortName, descriptionSite metadata
authorHome profile card and social links
contentWidthMain layout width
ui.navbar.stickySticky navbar switch
ui.dock.enabledBottom dock switch
navHeader navigation
footerNavFooter navigation
commentsGiscus settings
analyticsUmami settings
gallery, lightboxMarkdown image behavior
post.relatedCountRelated post count
post.licenseLicense block
export const siteConfig = {
name: 'Astro Narrow',
shortName: 'Narrow',
description: 'A content-focused Astro theme.',
contentWidth: '56rem'
}

Configure Content Types#

src/config/content.ts defines how each content type appears in navigation, lists, cards, and home sections.

OptionValues
cardStylearticle, showcase, compact
listLayoutstack, grid
gridColumns1, 2, 3
home.enabledShow the type on the home page
home.limitNumber of entries on the home page
home.featuredOnlyOnly show featured entries
src/config/content.ts
export const contentTypes = {
posts: {
collection: 'posts',
path: '/posts/',
label: { en: 'Posts', 'zh-cn': '文章' },
cardStyle: 'article',
listLayout: 'stack',
gridColumns: 1
}
}

Frontmatter#

Posts use Astro content collection fields. Keep frontmatter small and predictable.

FieldUse
titlePage title
descriptionSummary and meta description
pubDatePublish date
updatedDateOptional update date
coverCover image
tagsTag taxonomy
toccenter, side, true, or false
commentsPer-entry comments
math, mermaid, gallery, lightboxFeature hints

Project entries also support featured and links.

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 Features#

Note

Prefer Markdown-native input. Astro Narrow transforms common patterns with remark and rehype.

FeatureInput
AlertsGitHub style blockquotes
Tabs::::tabs and :::tab{title="..."}
GalleryConsecutive Markdown images
Math$x^2$ and $$...$$
MermaidFenced mermaid blocks
CodeExpressive Code fences

Code#

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

Math and Mermaid#

Inline math works as E=mc2E = mc^2.

flowchart LR A[Markdown] --> B[remark/rehype] B --> C[Astro components] C --> D[Static site]
License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.