mirror of
https://github.com/SphericalKat/medium.rip.git
synced 2026-10-21 01:34:22 +00:00
feat: add opengraph and twitter previews
Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
1 parent
c628ee7d6a
commit
3837d07495
3 files changed
+58
-14
No files matched your search
+20
-1
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user