Repos / s4g / b832bd2ec0
commit b832bd2ec001f9a8ddb38d94ad518f7484faf6c1
Author: Nhân <hi@imnhan.com>
Date: Mon Aug 21 23:54:41 2023 +0700
og:image must be full url apparently
Discord preview wouldn't work otherwise.
diff --git a/docs/_s4g/theme/base.tmpl b/docs/_s4g/theme/base.tmpl
index f27d1ad..710d06d 100644
--- a/docs/_s4g/theme/base.tmpl
+++ b/docs/_s4g/theme/base.tmpl
@@ -15,12 +15,12 @@
<meta property="og:description" content="{{.Post.Description}}" />
<meta name="twitter:description" content="{{.Post.Description}}" />
{{- end -}}
- {{- if .Post.Thumb -}}
- <meta property="og:image" content="{{.Post.Thumb}}" />
- <meta name="twitter:image" content="{{.Post.Thumb}}" />
+ {{- if .Post.OpenGraphImage -}}
+ <meta property="og:image" content="{{.Post.OpenGraphImage}}" />
+ <meta name="twitter:image" content="{{.Post.OpenGraphImage}}" />
{{- else if .Site.DefaultThumb -}}
- <meta property="og:image" content="{{.Site.Root}}{{.Site.DefaultThumb}}" />
- <meta name="twitter:image" content="{{.Site.Root}}{{.Site.DefaultThumb}}" />
+ <meta property="og:image" content="{{.Site.Address}}{{.Site.Root}}{{.Site.DefaultThumb}}" />
+ <meta name="twitter:image" content="{{.Site.Address}}{{.Site.Root}}{{.Site.DefaultThumb}}" />
{{- end }}
{{- if .Site.AuthorTwitter -}}
<meta name="twitter:site" content="{{.Site.AuthorTwitter}}" />
diff --git a/main.go b/main.go
index 1209e75..17c4b12 100644
--- a/main.go
+++ b/main.go
@@ -261,13 +261,17 @@ type Article struct {
OutputPath string
DjotBody []byte
ArticleMetadata
- WebPath string
- TemplatePaths []string
+ WebPath string
+ TemplatePaths []string
+ OpenGraphImage string
}
-func (a *Article) ComputeDerivedFields(root string) {
+func (a *Article) ComputeDerivedFields(addr, root string) {
a.WebPath = computeWebPath(root, a.OutputPath)
a.TemplatePaths = computeTemplatePaths(a.Path, a.Templates)
+ if a.Thumb != "" {
+ a.OpenGraphImage = addr + root + filepath.Dir(a.Path) + "/" + a.Thumb
+ }
}
func computeWebPath(root string, outputPath string) string {
@@ -393,7 +397,7 @@ func findArticles(fsys writablefs.FS, site *SiteMetadata) (map[string]Article, e
DjotBody: bodyText,
ArticleMetadata: meta,
}
- article.ComputeDerivedFields(site.Root)
+ article.ComputeDerivedFields(site.Address, site.Root)
result[article.Path] = article
return nil
})
diff --git a/theme/base.tmpl b/theme/base.tmpl
index f27d1ad..710d06d 100644
--- a/theme/base.tmpl
+++ b/theme/base.tmpl
@@ -15,12 +15,12 @@
<meta property="og:description" content="{{.Post.Description}}" />
<meta name="twitter:description" content="{{.Post.Description}}" />
{{- end -}}
- {{- if .Post.Thumb -}}
- <meta property="og:image" content="{{.Post.Thumb}}" />
- <meta name="twitter:image" content="{{.Post.Thumb}}" />
+ {{- if .Post.OpenGraphImage -}}
+ <meta property="og:image" content="{{.Post.OpenGraphImage}}" />
+ <meta name="twitter:image" content="{{.Post.OpenGraphImage}}" />
{{- else if .Site.DefaultThumb -}}
- <meta property="og:image" content="{{.Site.Root}}{{.Site.DefaultThumb}}" />
- <meta name="twitter:image" content="{{.Site.Root}}{{.Site.DefaultThumb}}" />
+ <meta property="og:image" content="{{.Site.Address}}{{.Site.Root}}{{.Site.DefaultThumb}}" />
+ <meta name="twitter:image" content="{{.Site.Address}}{{.Site.Root}}{{.Site.DefaultThumb}}" />
{{- end }}
{{- if .Site.AuthorTwitter -}}
<meta name="twitter:site" content="{{.Site.AuthorTwitter}}" />