weiro/providers/sitebuilder/tmpls.go
Leon Mika 30884372d6 feat: add pagination to generated site post list
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 14:37:42 +11:00

92 lines
2 KiB
Go

package sitebuilder
import (
"html/template"
"io/fs"
"time"
"lmika.dev/lmika/weiro/models"
"lmika.dev/lmika/weiro/models/pubmodel"
)
const (
// Template names
// tmplNamePostSingle is the template for single post (postSingleData)
tmplNamePostSingle = "posts_single.html"
// tmplNamePostList is the template for list of posts (postListData)
tmplNamePostList = "posts_list.html"
// tmplNameLayoutMain is the template for the main layout (layoutMainData)
tmplNameLayoutMain = "layout_main.html"
// tmplNameCategoryList is the template for the category index page
tmplNameCategoryList = "categories_list.html"
// tmplNameCategorySingle is the template for a single category page
tmplNameCategorySingle = "categories_single.html"
)
type Options struct {
BasePosts string // BasePosts is the base path for posts.
BaseUploads string // BaseUploads is the base path for uploads.
BaseStatic string // BaseStatic is the base path for static assets.
// TemplatesFS provides the raw templates for rendering the site.
TemplatesFS fs.FS
// StaticFS provides the raw assets for the site. This will be written as is
// from the BaseStatic dir.
StaticFS fs.FS
// FeedItems holds the number of posts to show in the feed.
FeedItems int
RenderTZ *time.Location
}
type commonData struct {
Site pubmodel.Site
}
type postSingleData struct {
commonData
Post *models.Post
HTML template.HTML
Path string
PostURL string
Categories []*models.Category
}
type postListData struct {
commonData
Posts []postSingleData
PageInfo models.PageInfo
PrevURL string
NextURL string
}
type layoutData struct {
commonData
Body template.HTML
}
type categoryListData struct {
commonData
Categories []categoryListItem
}
type categoryListItem struct {
models.CategoryWithCount
Path string
}
type categorySingleData struct {
commonData
Category *models.Category
DescriptionHTML template.HTML
Posts []postSingleData
Path string
}