Documentation
¶
Index ¶
- Variables
- func ArticleSchemaType(a Article) string
- func BuildShareUrl(urlTemplate string, article Article, settings Settings) template.URL
- func CopyHtmlResources(settings Settings, article *Article, resources []string) error
- func DateTimeFromString(date string) (time.Time, error)
- func EncodePathSegments(path string) string
- func ExtractResources(n *html.Node) []string
- func FormatMarkdown(article *Article, settings Settings, tmpl *texttemplate.Template, assets fs.FS) error
- func GenerateHtmlIndex(articles []Article, settings Settings, tmpl *texttemplate.Template, ...) error
- func GenerateRSS(articles []Article, settings Settings, tmpl *texttemplate.Template, ...) error
- func GetAvailableThemes(assets fs.FS) ([]string, error)
- func GetPaths(root string, extensions []string) ([]string, error)
- func GetThemeType(assets fs.FS, themeName string) string
- func IsImage(s string) bool
- func MimeTypeFromFilename(s string) string
- func RemoveDateFromPath(stringWithDate string) string
- func SaveThemeCSS(assets fs.FS, themeName string, outputDirectory string, ignoreErrors bool) error
- type Article
- type Settings
- type ShareButton
- type SiteTemplates
- type SortOrder
Constants ¶
This section is empty.
Variables ¶
var Markdown = goldmark.New( goldmark.WithRendererOptions( rendererhtml.WithUnsafe(), rendererhtml.WithHardWraps(), rendererhtml.WithXHTML(), ), goldmark.WithParserOptions( parser.WithAttribute(), parser.WithAutoHeadingID(), ), goldmark.WithExtensions( &frontmatter.Extender{}, mathjax.MathJax, extension.Table, extension.Strikethrough, extension.Linkify, extension.TaskList, extension.Footnote, extension.Typographer, ), )
Markdown is the configured Goldmark Markdown parser with frontmatter support.
Functions ¶
func ArticleSchemaType ¶ added in v0.0.28
ArticleSchemaType determines which schema.org type to use for an article.
func BuildShareUrl ¶ added in v0.0.27
BuildShareUrl replaces placeholders in the urlTemplate with encoded article data, and returns the final URL as a template.URL value.
func CopyHtmlResources ¶
CopyHtmlResources copies associated resources for an article and determines the article's output path. Resources include images and other linked assets.
func DateTimeFromString ¶
DateTimeFromString attempts to parse a date and time from a string using predefined regex patterns.
func EncodePathSegments ¶ added in v0.1.8
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
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
GetAvailableThemes scans the embedded assets for available CSS themes. It returns a sorted list of theme names (filenames without extension).
func GetPaths ¶
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
GetThemeType determines if a theme is "light" or "dark" by inspecting the CSS file.
func IsImage ¶ added in v0.0.27
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
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 ¶
RemoveDateFromPath attempts to remove date patterns from a given string.
func SaveThemeCSS ¶ added in v0.0.28
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.
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
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 {
}
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
ParseSortOrder converts a string into a SortOrder, validating supported options.