template

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LocalizedMonths = map[string][12]string{
	"id": {"Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"},
}

LocalizedMonths maps language codes to their month names. When a language code is present, FormatDate and FormatDateTime use it; otherwise Go's native English formatting is used.

Functions

func ComputeAssetHash added in v0.6.0

func ComputeAssetHash(theme *Theme) string

ComputeAssetHash reads base.css and style.css from the resolved static filesystem and returns a short combined hex hash for filename-based cache versioning. When either file is not found (e.g. broken theme), it returns "dev".

func EmbeddedStaticFS added in v0.11.0

func EmbeddedStaticFS() fs.FS

EmbeddedStaticFS returns the built-in static assets served under /static/ when no theme overrides them. The SSG exporter copies this tree as the base layer of the exported /static/ directory.

func FormatDate added in v0.6.0

func FormatDate(lang string, t time.Time) string

FormatDate returns a human-readable date string for the given time. When lang matches a key in LocalizedMonths, the localized month name is used. Otherwise Go's native English formatting ("January 2, 2006") is used.

func FormatDateTime added in v0.6.0

func FormatDateTime(lang string, t time.Time) string

FormatDateTime returns a human-readable date+time string for the given time. When lang matches a key in LocalizedMonths, the localized month name is used. Otherwise Go's native English formatting ("January 2, 2006 at 3:04 PM") is used.

func NewCompositeFSForTest

func NewCompositeFSForTest(primary, secondary fs.FS) fs.FS

NewCompositeFSForTest creates a compositeFS for testing purposes.

func ReadThemeStyles added in v0.7.0

func ReadThemeStyles(theme *Theme) (baseCSS, styleCSS string)

ReadThemeStyles reads base.css and style.css from the resolved static filesystem (theme overrides first, embedded defaults as fallback). The returned CSS is injected into AI text generation so generated HTML reuses the site's design tokens and component classes instead of inventing off-brand styles. A missing file yields an empty string for that slot — callers handle the empty case gracefully.

func ResolveFSForTest

func ResolveFSForTest(theme *Theme, embedded fs.FS, subPath string) fs.FS

ResolveFSForTest exposes resolveFS for testing purposes.

func RootFilesFS added in v0.11.0

func RootFilesFS(theme *Theme) fs.FS

RootFilesFS returns a filesystem over the theme's optional root/ directory, or nil when the theme is unset or ships no root/ directory. Files in that directory are served at the site root by the dynamic server and copied to the archive root by the static site generator.

func RootFilesHandler added in v0.11.0

func RootFilesHandler(theme *Theme, next http.Handler) http.Handler

RootFilesHandler wraps next with site-root serving of the theme's root/ directory. When the theme provides no root/ directory, next is returned unchanged.

func StaticFiles

func StaticFiles(theme *Theme) http.Handler

StaticFiles returns an http.Handler that serves the content site's static assets (CSS, JS). When a non-nil Theme with a non-empty Dir is provided, files on disk in that directory are served first, falling back to the embedded defaults for any file not present in the theme directory.

func ThemeStaticFS added in v0.11.0

func ThemeStaticFS(theme *Theme) fs.FS

ThemeStaticFS returns the active theme's static subtree on disk, or nil when no theme is configured or the theme ships no static directory. The SSG exporter copies it over the embedded layer so theme files win on name conflicts, mirroring the live server's resolution order.

Types

type AuthPageData

type AuthPageData struct {
	LayoutData
	// ShowRegister toggles the "create account" link on the login page. It is
	// false when self-registration is disabled (comments off), so visitors are
	// not pointed at a registration form that always fails.
	ShowRegister bool
}

type AuthorData

type AuthorData struct {
	LayoutData
	AuthorName            string
	Username              string
	AuthorAvatarURL       string
	Posts                 []PostItem
	CustomFieldsFormatted []FormattedField
	PaginationData
}

type CommentItem

type CommentItem struct {
	Author    string
	Text      string
	CreatedAt time.Time
}

type ContentData

type ContentData struct {
	LayoutData
	Slug                  string
	Body                  template.HTML
	Tags                  []string
	Author                string
	Username              string
	AuthorAvatarURL       string
	CreatedAt             time.Time
	AllowComments         bool
	CustomFields          map[string]any
	CustomFieldsFormatted []FormattedField
	Related               []PostItem
	Comments              []CommentItem
	PostType              string
	PostScripts           template.HTML
}

type FormattedField

type FormattedField struct {
	Label string
	Value string
}

type HomeSection added in v0.5.0

type HomeSection struct {
	PostTypeSlug string
	Title        string
	Description  string
	URL          string
	Posts        []PostItem
}

HomeSection is a per-post-type grouping rendered on the homepage. It is only populated when [[homepage_section]] blocks are configured in config.toml; an empty slice means the theme should fall back to the flat .Posts list.

type IndexData

type IndexData struct {
	LayoutData
	Posts    []PostItem
	Tags     []string
	Sections []HomeSection
	PaginationData
}
type LanguageLink struct {
	Code string
	Name string
	URL  string
}

type LayoutData

type LayoutData struct {
	Title           string
	Description     string
	OGTitle         string
	OGDesc          string
	OGImage         string
	PageTitle       string
	NavigationItems []NavigationItem
	CurrentPath     string
	Lang            string
	LanguageLinks   []LanguageLink
	SiteConfig      SiteConfig
}
type NavigationItem struct {
	Title    string
	URL      string
	IsActive bool
}

type NotFoundData

type NotFoundData struct {
	LayoutData
}

type PaginationData added in v0.5.0

type PaginationData struct {
	CurrentPage int
	HasPrev     bool
	HasNext     bool
	PrevURL     string
	NextURL     string
}

PaginationData carries prev/next state for paginated public listings. It is embedded in IndexData, AuthorData, and TagData so templates reach the fields directly (e.g. {{.NextURL}}). HasNext is derived from the fetch-limit+1 trick, so no COUNT query is required.

type PostItem

type PostItem struct {
	Slug            string
	Title           string
	MetaDescription string
	ImageURL        string
	ImageSrcset     string
	ImageSizes      string
	ImageVariants   map[string]string
	OriginalURL     string
	Author          string
	Username        string
	AuthorAvatarURL string
	CreatedAt       time.Time
	PostType        string
	Tags            []string
	CustomFields    map[string]any
}

type ResetPasswordData

type ResetPasswordData struct {
	LayoutData
}

type SiteConfig added in v0.5.0

type SiteConfig struct {
	Name string
}

SiteConfig carries the site-wide identity (name + optional logo) read from the optional [site_config] block in config.toml. It is the same on every page, so it lives on LayoutData rather than per-page data. Name is always populated (the handler defaults it to the application name); Logo is empty unless the operator configures one, in which case themes render an <img> (using Name as the alt text) instead of the name as text.

type TagData

type TagData struct {
	LayoutData
	TagName string
	Posts   []PostItem
	PaginationData
}

type Templates

type Templates struct {
	// contains filtered or unexported fields
}

func NewTemplates

func NewTemplates(theme *Theme, catalog *i18n.Catalog, postTypeSlugs ...string) (*Templates, error)

func (*Templates) RenderAuthor

func (t *Templates) RenderAuthor(w http.ResponseWriter, data AuthorData) error

func (*Templates) RenderAuthorToString added in v0.8.0

func (t *Templates) RenderAuthorToString(data AuthorData) (string, error)

func (*Templates) RenderContent

func (t *Templates) RenderContent(w http.ResponseWriter, data ContentData) error

func (*Templates) RenderContentToString added in v0.8.0

func (t *Templates) RenderContentToString(data ContentData) (string, error)

func (*Templates) RenderForgotPassword

func (t *Templates) RenderForgotPassword(w http.ResponseWriter, data AuthPageData) error

func (*Templates) RenderHome added in v0.6.0

func (t *Templates) RenderHome(w http.ResponseWriter, data IndexData) error

func (*Templates) RenderHomeToString added in v0.8.0

func (t *Templates) RenderHomeToString(data IndexData) (string, error)

func (*Templates) RenderIndex

func (t *Templates) RenderIndex(w http.ResponseWriter, data IndexData) error

func (*Templates) RenderIndexToString added in v0.8.0

func (t *Templates) RenderIndexToString(data IndexData) (string, error)

func (*Templates) RenderLogin

func (t *Templates) RenderLogin(w http.ResponseWriter, data AuthPageData) error

func (*Templates) RenderLoginToString added in v0.8.0

func (t *Templates) RenderLoginToString(data AuthPageData) (string, error)

func (*Templates) RenderNotFound

func (t *Templates) RenderNotFound(w http.ResponseWriter, data NotFoundData) error

func (*Templates) RenderNotFoundToString added in v0.8.0

func (t *Templates) RenderNotFoundToString(data NotFoundData) (string, error)

func (*Templates) RenderRegister

func (t *Templates) RenderRegister(w http.ResponseWriter, data AuthPageData) error

func (*Templates) RenderRegisterToString added in v0.8.0

func (t *Templates) RenderRegisterToString(data AuthPageData) (string, error)

func (*Templates) RenderResetPassword

func (t *Templates) RenderResetPassword(w http.ResponseWriter, data ResetPasswordData) error

func (*Templates) RenderTag

func (t *Templates) RenderTag(w http.ResponseWriter, data TagData) error

func (*Templates) RenderTagToString added in v0.8.0

func (t *Templates) RenderTagToString(data TagData) (string, error)

func (*Templates) RenderVerifyEmail

func (t *Templates) RenderVerifyEmail(w http.ResponseWriter, data VerifyEmailData) error

type Theme

type Theme struct {
	Dir string
}

Theme holds the path to a custom theme directory on disk. When Dir is empty, embedded defaults are used.

type VerifyEmailData

type VerifyEmailData struct {
	LayoutData
}

Jump to

Keyboard shortcuts

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