Fixed some bugs for publishing a first site
This commit is contained in:
parent
77d3ff4852
commit
3591e0c723
12 changed files with 86 additions and 30 deletions
|
|
@ -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()),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,23 @@ func New(fs fs.FS) *Provider {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Provider) ReadSite() (models.Sites, error) {
|
||||
func (p *Provider) ReadSite() (models.Site, error) {
|
||||
posts, err := p.ListPosts()
|
||||
if err != nil {
|
||||
return models.Sites{}, err
|
||||
return models.Site{}, err
|
||||
}
|
||||
|
||||
return models.Sites{
|
||||
meta := models.SiteMeta{}
|
||||
metaBytes, err := fs.ReadFile(p.fs, "site.yaml")
|
||||
if err != nil {
|
||||
return models.Site{}, err
|
||||
}
|
||||
if err := yaml.Unmarshal(metaBytes, &meta); err != nil {
|
||||
return models.Site{}, err
|
||||
}
|
||||
|
||||
return models.Site{
|
||||
Meta: meta,
|
||||
Posts: posts,
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -60,7 +70,7 @@ func (p *Provider) ReadPost(path string) (*models.Post, error) {
|
|||
return nil, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var meta models.Meta
|
||||
var meta models.PostMeta
|
||||
if err := yaml.Unmarshal(parts[1], &meta); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
func TestProvider_ReadPost(t *testing.T) {
|
||||
t.Run("with meta", func(t *testing.T) {
|
||||
testFS := fstest.MapFS{
|
||||
"site.yaml": {Data: []byte(`base_url: https://example.com`)},
|
||||
"posts/test.md": {Data: []byte(`---
|
||||
date: 2026-02-18T19:59:00Z
|
||||
title: Test Post Here
|
||||
|
|
@ -44,7 +45,7 @@ This is just a test post.
|
|||
|
||||
post, err := pr.ReadPost("posts/test.md")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, models.Meta{}, post.Meta)
|
||||
assert.Equal(t, models.PostMeta{}, post.Meta)
|
||||
assert.Equal(t, "This is just a test post.\n", post.Content)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue