template

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 12 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 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 ResolveFSForTest

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

ResolveFSForTest exposes resolveFS for testing purposes.

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.

Types

type AuthPageData

type AuthPageData struct {
	LayoutData
}

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
}

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
}

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) RenderContent

func (t *Templates) RenderContent(w http.ResponseWriter, data ContentData) 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) RenderIndex

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

func (*Templates) RenderLogin

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

func (*Templates) RenderNotFound

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

func (*Templates) RenderRegister

func (t *Templates) RenderRegister(w http.ResponseWriter, data AuthPageData) 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) 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