Fixed some bugs for publishing a first site

This commit is contained in:
Leon Mika 2026-02-18 22:38:05 +11:00
parent 77d3ff4852
commit 3591e0c723
12 changed files with 86 additions and 30 deletions

View file

@ -43,7 +43,6 @@ func New(site models.Site, opts Options) (*Builder, error) {
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
html.WithHardWraps(),
html.WithUnsafe(),
),
),
@ -79,7 +78,9 @@ func (b *Builder) renderPostList(ctx buildContext, postList []*models.Post) erro
return postCopy[i].Meta.Date.After(postCopy[j].Meta.Date)
})
pl := postListData{}
pl := postListData{
commonData: commonData{Site: b.site.Meta},
}
for _, post := range postCopy {
rp, err := b.renderPost(post)
if err != nil {
@ -105,9 +106,10 @@ func (b *Builder) renderPost(post *models.Post) (postSingleData, error) {
}
return postSingleData{
Path: postPath,
Meta: post.Meta,
HTML: template.HTML(md.String()),
commonData: commonData{Site: b.site.Meta},
Path: postPath,
Meta: post.Meta,
HTML: template.HTML(md.String()),
}, nil
}
@ -150,7 +152,8 @@ func (b *Builder) renderTemplate(w io.Writer, name string, data interface{}) err
}
return b.tmpls.ExecuteTemplate(w, tmplNameLayoutMain, layoutData{
Body: template.HTML(buf.String()),
commonData: commonData{Site: b.site.Meta},
Body: template.HTML(buf.String()),
})
}

View file

@ -33,16 +33,23 @@ type Options struct {
RenderTZ *time.Location
}
type commonData struct {
Site models.SiteMeta
}
type postSingleData struct {
commonData
Meta models.PostMeta
HTML template.HTML
Path string
}
type postListData struct {
commonData
Posts []postSingleData
}
type layoutData struct {
commonData
Body template.HTML
}