Improve link preview headers

This commit is contained in:
Zed 2021-01-07 23:58:29 +01:00
parent 4e1d213488
commit 768642a2cc

View file

@ -35,6 +35,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
images: seq[string] = @[]; ogTitle=""; theme=""; rss=""): VNode = images: seq[string] = @[]; ogTitle=""; theme=""; rss=""): VNode =
let ogType = let ogType =
if video.len > 0: "video" if video.len > 0: "video"
elif rss.len > 0: "object"
elif images.len > 0: "photo" elif images.len > 0: "photo"
else: "article" else: "article"
@ -45,15 +46,10 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
opensearchUrl = "http://" & cfg.hostname & "/opensearch" opensearchUrl = "http://" & cfg.hostname & "/opensearch"
buildHtml(head): buildHtml(head):
link(rel="preload", type="text/css", href="/css/style.css?v=3", `as`="style")
link(rel="preload", type="text/css", href="/css/fontello.css?v=2", `as`="style")
link(rel="preload", href="/fonts/fontello.woff2?21002321", `as`="font")
link(rel="stylesheet", type="text/css", href="/css/style.css?v=3") link(rel="stylesheet", type="text/css", href="/css/style.css?v=3")
link(rel="stylesheet", type="text/css", href="/css/fontello.css?v=2") link(rel="stylesheet", type="text/css", href="/css/fontello.css?v=2")
if theme.len > 0: if theme.len > 0:
link(rel="preload", type="text/css", href=(&"/css/themes/{theme}.css"), `as`="style")
link(rel="stylesheet", type="text/css", href=(&"/css/themes/{theme}.css")) link(rel="stylesheet", type="text/css", href=(&"/css/themes/{theme}.css"))
link(rel="apple-touch-icon", sizes="180x180", href="/apple-touch-icon.png") link(rel="apple-touch-icon", sizes="180x180", href="/apple-touch-icon.png")
@ -88,8 +84,14 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
meta(property="og:locale", content="en_US") meta(property="og:locale", content="en_US")
for url in images: for url in images:
meta(property="og:image", content=getPicUrl(url)) let image = "https://" & cfg.hostname & getPicUrl(url)
meta(property="twitter:card", content="summary_large_image") meta(property="og:image", content=image)
meta(property="twitter:image:src", content=image)
if rss.len > 0:
meta(property="twitter:card", content="summary")
else:
meta(property="twitter:card", content="summary_large_image")
if video.len > 0: if video.len > 0:
meta(property="og:video:url", content=video) meta(property="og:video:url", content=video)