use pointers to posts
6 files changed, 16 insertions(+), 16 deletions(-)
M internal/builder/builder.go → internal/builder/builder.go
@@ -92,7 +92,7 @@ if err := templates.PostPage(config, post).Render(ctx, buf); err != nil { return errors.WithMessage(err, "could not render post") } - if err := storage.WritePost(&post, buf); err != nil { + if err := storage.WritePost(post, buf); err != nil { return err } }@@ -108,7 +108,7 @@ } sitemap.AddPath("/tags/", lastMod) for _, tag := range cc.Tags.ToSlice() { - matchingPosts := []content.Post{} + matchingPosts := []*content.Post{} for _, post := range cc.Posts { if slices.Contains(post.Taxonomies.Tags, tag) { matchingPosts = append(matchingPosts, post)
M internal/builder/template/template.go → internal/builder/template/template.go
@@ -65,7 +65,7 @@ func RenderFeed( title string, config *config.Config, - posts []content.Post, + posts []*content.Post, specific string, ) (io.WriterTo, error) { buf := &bytes.Buffer{}
M internal/content/posts.go → internal/content/posts.go
@@ -55,8 +55,8 @@ type Collection struct { config *Config log *log.Logger - Posts []Post - Pages []Post + Posts []*Post + Pages []*Post StaticFiles []string Tags mapset.Set[string] }@@ -114,7 +114,7 @@ if err != nil { return nil, err } - if post.Date.IsZero() { + if post.Date.IsZero() && len(cs) > 1 { post.Date = cs[0].Date }@@ -175,13 +175,13 @@ for _, tag := range post.PostMatter.Taxonomies.Tags { cc.Tags.Add(strings.ToLower(tag)) } - cc.Posts = append(cc.Posts, *post) + cc.Posts = append(cc.Posts, post) } else { page, err := cc.GetPage(filename) if err != nil { return err } - cc.Pages = append(cc.Pages, *page) + cc.Pages = append(cc.Pages, page) } } else if !slices.Contains(SkipList, filename) { cc.StaticFiles = append(cc.StaticFiles, filename)@@ -193,9 +193,9 @@ } func NewContentCollection(config *Config, log *log.Logger) (*Collection, error) { cc := &Collection{ - Posts: []Post{}, + Posts: []*Post{}, Tags: mapset.NewSet[string](), - Pages: []Post{}, + Pages: []*Post{}, StaticFiles: []string{}, config: config, log: log,@@ -215,7 +215,7 @@ return cc.HandleFile(filename, d) }) - slices.SortFunc(cc.Posts, func(a, b Post) int { + slices.SortFunc(cc.Posts, func(a, b *Post) int { return b.Date.Compare(a.Date) })
M templates/homepage.templ → templates/homepage.templ
@@ -5,7 +5,7 @@ "go.alanpearce.eu/homestead/internal/config" "go.alanpearce.eu/homestead/internal/content" ) -templ Homepage(config *config.Config, posts []content.Post, content templ.Component) { +templ Homepage(config *config.Config, posts []*content.Post, content templ.Component) { @Layout(config, PageSettings{ Title: config.Title, TitleAttrs: templ.Attributes{
M templates/list.templ → templates/list.templ
@@ -5,7 +5,7 @@ "go.alanpearce.eu/homestead/internal/config" "go.alanpearce.eu/homestead/internal/content" ) -templ TagPage(config *config.Config, tag string, posts []content.Post, path string) { +templ TagPage(config *config.Config, tag string, posts []*content.Post, path string) { @Layout(config, PageSettings{ Title: tag, Path: path,@@ -24,7 +24,7 @@ @list(posts) } } -templ ListPage(config *config.Config, posts []content.Post, path string) { +templ ListPage(config *config.Config, posts []*content.Post, path string) { @Layout(config, PageSettings{ Title: config.Title, TitleAttrs: templ.Attributes{@@ -37,7 +37,7 @@ @list(posts) } } -templ list(posts []content.Post) { +templ list(posts []*content.Post) { <ul class="h-feed"> for _, post := range posts { <li class="h-entry">
M templates/post.templ → templates/post.templ
@@ -22,7 +22,7 @@ { d.Format("2006-01-02") } </time> } -templ PostPage(config *config.Config, post content.Post) { +templ PostPage(config *config.Config, post *content.Post) { @Layout(config, PageSettings{ Title: post.Title, TitleAttrs: templ.Attributes{