parse

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Markdown is the configured Goldmark Markdown parser with frontmatter support.

Functions

func ArticleSchemaType added in v0.0.28

func ArticleSchemaType(a Article) string

ArticleSchemaType determines which schema.org type to use for an article.

func BuildShareUrl added in v0.0.27

func BuildShareUrl(urlTemplate string, article Article, settings Settings) template.URL

BuildShareUrl replaces placeholders in the urlTemplate with encoded article data, and returns the final URL as a template.URL value.

func CopyHtmlResources

func CopyHtmlResources(settings Settings, article *Article, resources []string) error

CopyHtmlResources copies associated resources for an article and determines the article's output path. Resources include images and other linked assets.

func DateTimeFromString

func DateTimeFromString(date string) (time.Time, error)

DateTimeFromString attempts to parse a date and time from a string using predefined regex patterns.

func EncodePathSegments added in v0.1.8

func EncodePathSegments(path string) string

EncodePathSegments splits a path by slashes and URL-encodes each segment, preserving the structure for valid URIs (e.g. "foo bar/baz.jpg" -> "foo%20bar/baz.jpg"). It assumes forward slashes are the separator.

func ExtractResources added in v0.0.27

func ExtractResources(n *html.Node) []string

ExtractResources traverses an HTML node tree and extracts src/href/data values from tags like img, script, link, video, audio, source, track, object, iframe, and a.

func FormatMarkdown

func FormatMarkdown(article *Article, settings Settings, tmpl *texttemplate.Template, assets fs.FS) error

FormatMarkdown applies an HTML template to the Markdown content of an article. It injects article and settings into the provided template and updates HtmlContent.

func GenerateHtmlIndex

func GenerateHtmlIndex(articles []Article, settings Settings, tmpl *texttemplate.Template, assets fs.FS) error

GenerateHtmlIndex creates an HTML index page listing all processed articles using the provided template and settings.

func GenerateRSS

func GenerateRSS(articles []Article, settings Settings, tmpl *texttemplate.Template, assets fs.FS) error

GenerateRSS creates an RSS feed XML file from the processed articles. It sorts articles by creation date in descending order and writes rss.xml into the output directory.

func GetAvailableThemes added in v0.0.28

func GetAvailableThemes(assets fs.FS) ([]string, error)

GetAvailableThemes scans the embedded assets for available CSS themes. It returns a sorted list of theme names (filenames without extension).

func GetPaths

func GetPaths(root string, extensions []string) ([]string, error)

GetPaths retrieves all file paths within a directory and its subdirectories matching the provided list of file extensions.

func GetThemeType added in v0.0.28

func GetThemeType(assets fs.FS, themeName string) string

GetThemeType determines if a theme is "light" or "dark" by inspecting the CSS file.

func IsImage added in v0.0.27

func IsImage(s string) bool

IsImage reports whether a filename has a common image extension. It is exported so it can be used by main and templates.

func MimeTypeFromFilename added in v0.1.9

func MimeTypeFromFilename(s string) string

MimeTypeFromFilename returns a best-effort MIME type for a given filename or path. It falls back to "image/jpeg" to preserve backwards-compatible behavior for unknown types.

func RemoveDateFromPath

func RemoveDateFromPath(stringWithDate string) string

RemoveDateFromPath attempts to remove date patterns from a given string.

func SaveThemeCSS added in v0.0.28

func SaveThemeCSS(assets fs.FS, themeName string, outputDirectory string, ignoreErrors bool) error

SaveThemeCSS copies the selected theme CSS file from embedded assets to style.css in the output directory. If themeName is empty or invalid, it attempts to use "default.css".

Types

type Article

type Article struct {
	Title        string
	Description  string
	CoverImage   string
	Created      time.Time
	Updated      time.Time
	Tags         []string
	TextContent  string
	HtmlContent  string // Full HTML page content (with head, body, etc.)
	BodyContent  string // Inner HTML body content (for RSS)
	OriginalPath string
	LinkToSelf   string
	LinkToSave   string
	ExternalLink string
	CanonicalUrl string
}

Article models a single article or page, regardless of its original format.

func HTMLFile

func HTMLFile(path string, settings Settings) (Article, []string, error)

HTMLFile parses an HTML file, extracts metadata, and populates an Article. It returns the Article and a list of extracted resources.

func MarkdownFile

func MarkdownFile(path string, settings Settings) (Article, []string, error)

MarkdownFile parses a Markdown file, extracts frontmatter, and populates an Article. It returns the Article and a list of extracted resource paths (e.g., images).

type Settings

type Settings struct {
	Title                     string
	DescriptionMarkdown       string
	DescriptionHTML           template.HTML
	InputPath                 string
	OutputPath                string
	DateFormat                string
	IndexName                 string
	Theme                     string
	Lang                      string
	PathToCustomCss           string
	PathToCustomJs            string
	PathToCustomFavicon       string
	AdditionalElementsTop     template.HTML
	AdditionalElementsBottom  template.HTML
	DoNotExtractTagsFromPaths bool
	DoNotRemoveDateFromPaths  bool
	DoNotRemoveDateFromTitles bool
	OpenInNewTab              bool
	BaseUrl                   string
	ShareButtons              []ShareButton
	Sort                      SortOrder
	HighlightTheme            string
	Port                      string
	ForceOverwrite            bool
	IgnoreErrors              bool
	BuildVersion              string

	// AuthorName is used in meta tags and structured data as the article author.
	AuthorName string
	// PublisherName is used in structured data as the publisher name.
	PublisherName string
	// PublisherLogoPath is an optional path (relative to site root) to a logo image used
	// in structured data as publisher.logo.
	PublisherLogoPath string
}

Settings holds global configuration for site generation.

type ShareButton added in v0.0.27

type ShareButton struct {
	Name        string
	Display     string
	UrlTemplate string
}

ShareButton describes a single social or custom share target.

type SiteTemplates added in v0.0.27

type SiteTemplates struct {
	Article *texttemplate.Template
	Index   *texttemplate.Template
	RSS     *texttemplate.Template
}

SiteTemplates holds the pre-parsed templates for articles, index, and RSS.

func LoadTemplates added in v0.0.27

func LoadTemplates(assets fs.FS) (SiteTemplates, error)

LoadTemplates parses all necessary templates from the embedded assets once at startup. It returns a SiteTemplates struct with initialized template pointers.

type SortOrder added in v0.0.28

type SortOrder string

SortOrder is a strongly-typed representation of article sort order.

const (
	SortDateCreated        SortOrder = "date-created"
	SortReverseDateCreated SortOrder = "reverse-date-created"
	SortDateUpdated        SortOrder = "date-updated"
	SortReverseDateUpdated SortOrder = "reverse-date-updated"
	SortTitle              SortOrder = "title"
	SortReverseTitle       SortOrder = "reverse-title"
	SortPath               SortOrder = "path"
	SortReversePath        SortOrder = "reverse-path"
)

Supported SortOrder values.

func ParseSortOrder added in v0.0.28

func ParseSortOrder(s string) (SortOrder, error)

ParseSortOrder converts a string into a SortOrder, validating supported options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL