Documentation
¶
Index ¶
- func ExtractSummary(markdown, html string, maxWords int) string
- func GenerateTOC(html string, minLevel, maxLevel int, tocID ...string) string
- func ReadingTime(wordCount int) int
- func StripHTML(s string) string
- func TOCFromEntries(entries []*TOCEntry, tocID ...string) string
- func WordCount(text string) int
- func WrapHeadingSections(html string) string
- type HighlightOptions
- type Page
- type Parser
- type TOCEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractSummary ¶
ExtractSummary extracts a plain-text summary from markdown and rendered HTML. Priority: 1) Content before <!--more-->, 2) First paragraph, 3) Truncated content. The result is always plain text — HTML tags and footnote references are stripped so the summary is safe for meta descriptions, RSS feeds, and templ text nodes.
func GenerateTOC ¶
GenerateTOC extracts headings from HTML and generates a table of contents. minLevel and maxLevel control which heading levels to include (default: 2-4). The optional tocID parameter scopes the TOC for go-components JS scroll-spy; when provided, each link gets data-tui-toc-id for IntersectionObserver binding.
func ReadingTime ¶
ReadingTime estimates reading time in minutes (assumes 200 words per minute)
func StripHTML ¶
StripHTML removes HTML tags from a string and decodes HTML entities to their plain-text equivalents (e.g. “ → ", & → &).
func TOCFromEntries ¶
TOCFromEntries builds TOC HTML from a slice of entries (alternative API). The optional tocID parameter enables go-components JS scroll-spy binding.
func WrapHeadingSections ¶
WrapHeadingSections wraps each h2-delimited block of HTML in <section> tags. Content before the first h2 is wrapped in its own section. This enables CSS structural selectors like section:nth-of-type(even) for alternating backgrounds via the token system.
Input: <h2 id="a">A</h2><p>...</p><h2 id="b">B</h2><p>...</p> Output: <section><h2 id="a">A</h2><p>...</p></section><section><h2 id="b">B</h2><p>...</p></section>
Types ¶
type HighlightOptions ¶
type HighlightOptions struct {
Style string // Chroma style name (e.g. "monokai", "github")
LineNumbers bool // Show line numbers in code blocks
}
HighlightOptions configures syntax highlighting in the parser. Pass to NewParser to enable Chroma-based code highlighting.
type Page ¶
type Page struct {
// Path is the original file path
Path string
// Content is the rendered HTML content
Content string
// RawContent is the original markdown (for custom processing)
RawContent string
// Frontmatter contains the parsed YAML frontmatter
Frontmatter map[string]any
// Layout specifies which layout template to use
Layout string
// URL is the generated URL path for this page
URL string
// Date is the publication date
Date time.Time
// Draft indicates if this is a draft post
Draft bool
// Title is extracted from frontmatter
Title string
// Description is extracted from frontmatter
Description string
// Tags are extracted from frontmatter
Tags []string
// Author is extracted from frontmatter
Author string
// Section is the content section (e.g., "blog" from content/blog/post.md)
Section string
// Weight is used for manual ordering (from frontmatter)
Weight int
// Summary is the page summary (first paragraph or content before <!--more-->)
Summary string
// WordCount is the number of words in the content
WordCount int
// ReadingTime is the estimated reading time in minutes
ReadingTime int
// TOC is the rendered table of contents HTML
TOC string
// Prev is the previous page in the section (by date)
Prev *Page
// Next is the next page in the section (by date)
Next *Page
// Aliases are alternative URLs that redirect to this page
Aliases []string
}
Page represents a parsed content page with metadata
func (*Page) IsPublished ¶
IsPublished returns true if the page is not a draft and has a past or current date
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles parsing of Markdown content files
func NewParser ¶
func NewParser(contentDir string, opts ...HighlightOptions) *Parser
NewParser creates a new Parser instance. Pass a HighlightOptions to enable syntax highlighting; omit it to disable highlighting.