Support video embeds

Fixes #66
This commit is contained in:
Zed
2019-12-06 15:15:56 +01:00
parent f9c4acabf8
commit ebd7afe464
10 changed files with 98 additions and 37 deletions

19
src/views/embed.nim Normal file
View File

@@ -0,0 +1,19 @@
import options
import karax/[karaxdsl, vdom]
import ".."/[types, formatters]
import general, tweet
const doctype = "<!DOCTYPE html>\n"
proc renderVideoEmbed*(cfg: Config; tweet: Tweet): string =
let thumb = get(tweet.video).thumb
let vidUrl = getVideoEmbed(cfg, tweet.id)
let prefs = Prefs(hlsPlayback: true)
let node = buildHtml(html(lang="en")):
renderHead(prefs, cfg, `type`="video", images = @[thumb], video=vidUrl)
tdiv(class="embed-video"):
renderVideo(get(tweet.video), prefs, "")
result = doctype & $node

View File

@@ -28,49 +28,54 @@ proc renderNavbar*(title, rss: string; req: Request): VNode =
icon "info-circled", title="About", href="/about"
iconReferer "cog", "/settings", path, title="Preferences"
proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; `type`="article";
video=""; images: seq[string] = @[]): VNode =
buildHtml(head):
link(rel="stylesheet", `type`="text/css", href="/css/style.css")
link(rel="stylesheet", `type`="text/css", href="/css/fontello.css")
link(rel="apple-touch-icon", sizes="180x180", href="/apple-touch-icon.png")
link(rel="icon", type="image/png", sizes="32x32", href="/favicon-32x32.png")
link(rel="icon", type="image/png", sizes="16x16", href="/favicon-16x16.png")
link(rel="manifest", href="/site.webmanifest")
link(rel="mask-icon", href="/safari-pinned-tab.svg", color="#ff6c60")
if prefs.hlsPlayback:
script(src="/js/hls.light.min.js")
script(src="/js/hlsPlayback.js")
title:
if titleText.len > 0:
text titleText & " | " & cfg.title
else:
text cfg.title
meta(name="viewport", content="width=device-width, initial-scale=1.0")
meta(property="og:type", content=`type`)
meta(property="og:title", content=titleText)
meta(property="og:description", content=stripHtml(desc))
meta(property="og:site_name", content="Nitter")
for url in images:
meta(property="og:image", content=getPicUrl(url))
if video.len > 0:
meta(property="og:video:url", content=video)
meta(property="og:video:secure_url", content=video)
meta(property="og:video:type", content="text/html")
proc renderMain*(body: VNode; req: Request; cfg: Config; titleText=""; desc="";
rss=""; `type`="article"; video=""; images: seq[string] = @[]): string =
let prefs = getPrefs(req.cookies.getOrDefault("preferences"), cfg)
let theme = toLowerAscii(prefs.theme).replace(" ", "_")
let node = buildHtml(html(lang="en")):
head:
link(rel="stylesheet", `type`="text/css", href="/css/style.css")
link(rel="stylesheet", `type`="text/css", href="/css/fontello.css")
renderHead(prefs, cfg, titleText, desc, `type`, video, images):
if theme.len > 0:
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="icon", type="image/png", sizes="32x32", href="/favicon-32x32.png")
link(rel="icon", type="image/png", sizes="16x16", href="/favicon-16x16.png")
link(rel="manifest", href="/site.webmanifest")
link(rel="mask-icon", href="/safari-pinned-tab.svg", color="#ff6c60")
if rss.len > 0:
link(rel="alternate", `type`="application/rss+xml", href=rss, title="RSS feed")
if prefs.hlsPlayback:
script(src="/js/hls.light.min.js")
script(src="/js/hlsPlayback.js")
title:
if titleText.len > 0:
text titleText & " | " & cfg.title
else:
text cfg.title
meta(name="viewport", content="width=device-width, initial-scale=1.0")
meta(property="og:type", content=`type`)
meta(property="og:title", content=titleText)
meta(property="og:description", content=stripHtml(desc))
meta(property="og:site_name", content="Nitter")
for url in images:
meta(property="og:image", content=getPicUrl(url))
if video.len > 0:
meta(property="og:video:url", content=video)
meta(property="og:video:secure_url", content=video)
body:
renderNavbar(cfg.title, rss, req)

View File

@@ -75,7 +75,7 @@ proc renderVideoUnavailable(video: Video): VNode =
else:
p: text "This media is unavailable"
proc renderVideo(video: Video; prefs: Prefs; path: string): VNode =
proc renderVideo*(video: Video; prefs: Prefs; path: string): VNode =
let container =
if video.description.len > 0 or video.title.len > 0: " card-container"
else: ""