feat: add opengraph and twitter previews

Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
sphericalkat committed 2023-05-28 23:51:48 +05:30
1 parent c628ee7d6a
commit 3837d07495
3 files changed
+58 -14

No files matched your search

+20 -1
View File
@@ -1,6 +1,7 @@
package routes
import (
"fmt"
"html/template"
"time"
@@ -23,7 +24,22 @@ func show(c *fiber.Ctx) error {
post := e.Data.Post
publishDate := time.UnixMilli(e.Data.Post.CreatedAt)
p := converters.ConvertParagraphs(post.Content.BodyModel.Paragraphs)
paragraphs := post.Content.BodyModel.Paragraphs
p := converters.ConvertParagraphs(paragraphs)
desc := ""
if len(paragraphs) >= 0 {
desc = paragraphs[1].Text
}
imgUrl := ""
for _, p := range paragraphs {
if p.Type == "IMG" {
imgUrl = fmt.Sprintf("https://miro.medium.com/v2/resize:fit:1200/%s", p.Metadata.ID)
break
}
}
return c.Render("show", fiber.Map {
"Title": post.Title,
@@ -31,6 +47,9 @@ func show(c *fiber.Ctx) error {
"Author": post.Creator.Name,
"PublishDate": publishDate.Format(time.DateOnly),
"Paragraphs": template.HTML(p),
"Description": desc,
"Path": c.Path(),
"Image": imgUrl,
})
}