oembed support for videos
This commit is contained in:
parent
cc1f7d706c
commit
819efc6d93
3 changed files with 24 additions and 3 deletions
|
@ -34,3 +34,6 @@ proc createEmbedRouter*(cfg: Config) =
|
|||
redirect(&"/i/status/{id}/embed")
|
||||
else:
|
||||
resp Http404
|
||||
|
||||
get "/oembed.json":
|
||||
respJson generateOembed(cfg, @"type", @"title", @"user", @"url")
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import options, algorithm, sequtils
|
||||
import options, algorithm, sequtils, json
|
||||
import karax/[karaxdsl, vdom]
|
||||
from jester import Request
|
||||
|
||||
import ../types
|
||||
import ".."/[types, formatters]
|
||||
import general, tweet
|
||||
|
||||
const doctype = "<!DOCTYPE html>\n"
|
||||
|
@ -22,3 +22,14 @@ proc renderVideoEmbed*(tweet: Tweet; cfg: Config; req: Request): string =
|
|||
renderVideo(video, prefs, "")
|
||||
|
||||
result = doctype & $node
|
||||
|
||||
proc generateOembed*(cfg: Config; typ, title, user, url: string): JsonNode =
|
||||
%*{
|
||||
"type": typ,
|
||||
"version": "1.0",
|
||||
"provider_name": "Nitter",
|
||||
"provider_url": getUrlPrefix(cfg),
|
||||
"title": title,
|
||||
"author_name": user,
|
||||
"author_url": url
|
||||
}
|
|
@ -91,6 +91,9 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
|
|||
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
||||
meta(name="theme-color", content="#1F1F1F")
|
||||
meta(property="og:type", content=ogType)
|
||||
if video.len > 0:
|
||||
meta(property="og:title", content=stripHtml(desc))
|
||||
else:
|
||||
meta(property="og:title", content=(if ogTitle.len > 0: ogTitle else: titleText))
|
||||
meta(property="og:description", content=stripHtml(desc))
|
||||
meta(property="og:site_name", content="Nitter")
|
||||
|
@ -119,6 +122,10 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
|
|||
meta(property="og:video:url", content=video)
|
||||
meta(property="og:video:secure_url", content=video)
|
||||
meta(property="og:video:type", content="video/mp4")
|
||||
verbatim &"<link rel=\"alternate\" href=\"{getUrlPrefix(cfg)}/oembed.json?type=video&title={encodeUrl(stripHtml(desc))}&user={encodeUrl(if ogTitle.len > 0: ogTitle else: titleText)}\" type=\"application/json+oembed\" />"
|
||||
#link(rel="alternate",
|
||||
# href=getUrlPrefix(cfg) & "/oembed.json?type=video&title=" & encodeUrl(stripHtml(desc)) & "&user=" & encodeUrl(if ogTitle.len > 0: ogTitle else: titleText),
|
||||
# `type`="application/json+oembed")
|
||||
|
||||
# this is last so images are also preloaded
|
||||
# if this is done earlier, Chrome only preloads one image for some reason
|
||||
|
|
Loading…
Reference in a new issue