Documentation
¶
Overview ¶
Package content loads Markdown collections from an app's src/content directory, with typed YAML front matter:
// src/content/blog/hello-world.md
---
title: Hello, world
date: 2026-11-10
---
The first post.
type Post struct {
Title string `yaml:"title" json:"title"`
Date time.Time `yaml:"date" json:"date"`
}
var posts = &content.Collection[Post]{Dir: "blog", Sort: content.Newest(func(p Post) time.Time { return p.Date })}
func Load(ctx *kit.Ctx) (PageData, error) {
post, err := posts.Get(ctx, ctx.Param("slug")) // a 404 if there is none
...
}
Entries render to HTML with GitHub-flavored Markdown, heading IDs, footnotes and highlighted code; show it with {@html entry.html}. The collection is read once in production and on every request under tern dev. Entries with `draft: true` in their front matter are left out in production.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CodeCSS ¶
CodeCSS returns the CSS for highlighted code in a chroma style, such as "github", "github-dark" or "dracula". Serve it, or paste it into app.css.
Types ¶
type Collection ¶
type Collection[T any] struct { // Dir is the collection's directory relative to src/content. Dir string // Sort orders All; the default is by slug. Sort func(a, b Entry[T]) int // Filter, if set, leaves out entries for which it returns false. Filter func(Entry[T]) bool // contains filtered or unexported fields }
Collection is a directory of Markdown files below src/content. Declare it once, as a package variable, so production loads it once.
func (*Collection[T]) All ¶
func (c *Collection[T]) All(ctx *kit.Ctx) ([]Entry[T], error)
All returns every entry, sorted.
type Entry ¶
type Entry[T any] struct { // Slug is the file's path in the collection without ".md", such as // "hello-world" or "guides/install"; "guides/index.md" is "guides". Slug string `json:"slug"` // Data is the decoded front matter. Data T `json:"data"` // HTML is the rendered body. HTML string `json:"html"` // Headings lists the h2 to h4 headings. Headings []Heading `json:"headings"` // Excerpt is the first paragraph as plain text. Excerpt string `json:"excerpt"` // ReadingMinutes estimates the reading time. ReadingMinutes int `json:"readingMinutes"` }
Entry is one Markdown file of a collection.