From 4d83aea45528477d59d5c204cb369ab1236d61e0 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Mon, 6 Jan 2025 09:55:39 -0300 Subject: [PATCH] feat(blog): summary from markdown --- handlers/pages/blog.templ | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/handlers/pages/blog.templ b/handlers/pages/blog.templ index 41b0026..a134b97 100644 --- a/handlers/pages/blog.templ +++ b/handlers/pages/blog.templ @@ -4,6 +4,7 @@ import ( "bytes" "io" "encoding/json" + "strings" "errors" "fmt" "net/http" @@ -19,6 +20,8 @@ import ( "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark-meta" + "github.com/yuin/goldmark/text" + "github.com/yuin/goldmark/ast" ) type EntryTemplate func([]byte) templ.Component @@ -162,6 +165,16 @@ func (p *Blog) init() error { return ast.WalkSkipChildren, nil } + if n.Kind() == ast.KindParagraph && summary == "" { + var tbuf bytes.Buffer + p.md.Renderer().Render(&tbuf, body, n) + summary = tbuf.String() + + log.Printf("FOUND SUMMARY %q", summary) + + return ast.WalkSkipChildren, nil + } + return ast.WalkContinue, nil }) if err != nil {