mirror of
https://github.com/SphericalKat/medium.rip.git
synced 2024-11-16 11:25:57 +00:00
feat: add opengraph and twitter previews
Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
parent
c628ee7d6a
commit
3837d07495
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,43 @@
|
||||
rel="stylesheet">
|
||||
|
||||
<title>{{ .Title }}</title>
|
||||
|
||||
<meta property="og:type" content="object">
|
||||
<meta property="og:title" content="{{ .Title }}">
|
||||
<meta property="og:image" content="{{.Image}}">
|
||||
|
||||
<meta name="twitter:title" content="{{ .Title }}">
|
||||
<meta itemprop="name" content="{{ .Title }}">
|
||||
<meta name="application-name" content="{{ .Title }}">
|
||||
<meta property="og:site_name" content="{{ .Title }}">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<meta property="og:locale" content="en">
|
||||
<meta name="language" content="en">
|
||||
<meta name="twitter:card" content="summary">
|
||||
<meta name="twitter:site" content="@Spherical_Kat">
|
||||
|
||||
<meta name="robots" content="index,follow">
|
||||
<meta name="googlebot" content="index,follow">
|
||||
<meta name="keywords" content="medium,blog,frontend,alternative,technology,golang,go">
|
||||
<meta name="coverage" content="Worldwide">
|
||||
<meta name="distribution" content="Global">
|
||||
<meta name="HandheldFriendly" content="True">
|
||||
<meta name="HandheldFriendly" content="True">
|
||||
<meta name="apple-mobile-web-app-title" content="{{ .Title }}">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="apple-touch-fullscreen" content="yes">
|
||||
|
||||
<meta name="description" content="{{.Description}}">
|
||||
<meta itemprop="description" content={{.Description}}>
|
||||
<meta property="og:description" content={{.Description}}>
|
||||
<meta name="twitter:description" content={{.Description}}>
|
||||
|
||||
<meta name="url" content="https://medium.rip/{{.Path}}">
|
||||
<meta name="twitter:url" content="https://medium.rip/{{.Path}}">
|
||||
<meta property="og:url" content="https://medium.rip/{{.Path}}">
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body class="flex flex-col h-full w-full items-center">
|
||||
|
@ -40,19 +40,7 @@ func (i *Image) width() int64 {
|
||||
}
|
||||
|
||||
func (i *Image) src() string {
|
||||
return fmt.Sprintf("%s/%d/%d/%s", IMAGE_HOST, i.width(), i.height(), i.ID)
|
||||
}
|
||||
|
||||
func (i *Image) height() int64 {
|
||||
if i.OriginalWidth > MAX_WIDTH {
|
||||
return i.OriginalHeight * int64(i.ratio())
|
||||
} else {
|
||||
return i.OriginalHeight
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Image) ratio() float32 {
|
||||
return float32(MAX_WIDTH) / float32(i.OriginalWidth)
|
||||
return fmt.Sprintf("https://miro.medium.com/v2/resize:fit:1200/%s", i.ID)
|
||||
}
|
||||
|
||||
func ConvertParagraphs(paragraphs []entities.Paragraph) string {
|
||||
|
Loading…
Reference in New Issue
Block a user