2026-02-18 11:07:18 +00:00
|
|
|
package sitebuilder
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"html/template"
|
|
|
|
|
"io/fs"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"lmika.dev/lmika/weiro/models"
|
2026-02-19 10:21:27 +00:00
|
|
|
"lmika.dev/lmika/weiro/models/pubmodel"
|
2026-02-18 11:07:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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"
|
2026-03-18 10:51:19 +00:00
|
|
|
|
|
|
|
|
// 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"
|
2026-02-18 11:07:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
|
// BasePosts is the base path for posts.
|
|
|
|
|
BasePosts string
|
|
|
|
|
|
|
|
|
|
// TemplatesFS provides the raw templates for rendering the site.
|
|
|
|
|
TemplatesFS fs.FS
|
|
|
|
|
|
2026-03-05 11:04:24 +00:00
|
|
|
// FeedItems holds the number of posts to show in the feed.
|
|
|
|
|
FeedItems int
|
|
|
|
|
|
2026-02-18 11:07:18 +00:00
|
|
|
RenderTZ *time.Location
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:38:05 +00:00
|
|
|
type commonData struct {
|
2026-02-19 10:21:27 +00:00
|
|
|
Site pubmodel.Site
|
2026-02-18 11:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:07:18 +00:00
|
|
|
type postSingleData struct {
|
2026-02-18 11:38:05 +00:00
|
|
|
commonData
|
2026-03-18 10:51:19 +00:00
|
|
|
Post *models.Post
|
|
|
|
|
HTML template.HTML
|
|
|
|
|
Path string
|
|
|
|
|
PostURL string
|
|
|
|
|
Categories []*models.Category
|
2026-02-18 11:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type postListData struct {
|
2026-02-18 11:38:05 +00:00
|
|
|
commonData
|
2026-02-18 11:07:18 +00:00
|
|
|
Posts []postSingleData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type layoutData struct {
|
2026-02-18 11:38:05 +00:00
|
|
|
commonData
|
2026-02-18 11:07:18 +00:00
|
|
|
Body template.HTML
|
|
|
|
|
}
|
2026-03-18 10:51:19 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|