timestamps and avatars on text only posts

This commit is contained in:
Cynthia Foxwell 2024-10-29 19:36:38 -06:00
parent 04f745c5eb
commit f5fadca631
5 changed files with 46 additions and 23 deletions

4
.gitignore vendored
View file

@ -13,3 +13,7 @@ nitter.conf
guest_accounts.json* guest_accounts.json*
dump.rdb dump.rdb
proxy/node_modules proxy/node_modules
*.dll
*.exe
*.pem
Caddyfile

View file

@ -36,4 +36,4 @@ proc createEmbedRouter*(cfg: Config) =
resp Http404 resp Http404
get "/oembed.json": get "/oembed.json":
respJson generateOembed(cfg, @"type", @"title", @"user", @"url") respJson generateOembed(cfg, @"type", @"title", @"user", @"url", @"provider")

View file

@ -67,6 +67,8 @@ proc createStatusRouter*(cfg: Config) =
title = pageTitle(conv.tweet) title = pageTitle(conv.tweet)
ogTitle = pageTitle(conv.tweet.user) ogTitle = pageTitle(conv.tweet.user)
desc = conv.tweet.text desc = conv.tweet.text
avatar = conv.tweet.user.userPic
time = some(conv.tweet.time)
var var
images = conv.tweet.photos images = conv.tweet.photos
@ -93,7 +95,7 @@ proc createStatusRouter*(cfg: Config) =
let html = renderConversation(conv, prefs, getPath() & "#m") let html = renderConversation(conv, prefs, getPath() & "#m")
resp renderMain(html, request, cfg, prefs, title, desc, ogTitle, resp renderMain(html, request, cfg, prefs, title, desc, ogTitle,
images=images, video=video) images=images, video=video, avatar=avatar, time=time)
get "/@name/@s/@id/@m/?@i?": get "/@name/@s/@id/@m/?@i?":
cond @"s" in ["status", "statuses"] cond @"s" in ["status", "statuses"]

View file

@ -23,11 +23,11 @@ proc renderVideoEmbed*(tweet: Tweet; cfg: Config; req: Request): string =
result = doctype & $node result = doctype & $node
proc generateOembed*(cfg: Config; typ, title, user, url: string): JsonNode = proc generateOembed*(cfg: Config; typ, title, user, url, provider: string): JsonNode =
%*{ %*{
"type": typ, "type": typ,
"version": "1.0", "version": "1.0",
"provider_name": "Nitter", "provider_name": provider,
"provider_url": getUrlPrefix(cfg), "provider_url": getUrlPrefix(cfg),
"title": title, "title": title,
"author_name": user, "author_name": user,

View file

@ -1,5 +1,5 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
import uri, strutils, strformat import uri, strutils, strformat, times, options
import karax/[karaxdsl, vdom] import karax/[karaxdsl, vdom]
import renderutils import renderutils
@ -38,7 +38,8 @@ proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode =
proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc=""; proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
video=""; images: seq[string] = @[]; banner=""; ogTitle=""; video=""; images: seq[string] = @[]; banner=""; ogTitle="";
rss=""; canonical=""): VNode = rss=""; canonical=""; avatar="";
time: Option[DateTime] = none(DateTime)): VNode =
var theme = prefs.theme.toTheme var theme = prefs.theme.toTheme
if "theme" in req.params: if "theme" in req.params:
theme = req.params["theme"].toTheme theme = req.params["theme"].toTheme
@ -99,26 +100,41 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
else: else:
meta(property="og:title", content=finalizedTitleText) meta(property="og:title", content=finalizedTitleText)
meta(property="og:description", content=finalizedDesc) meta(property="og:description", content=finalizedDesc)
meta(property="og:site_name", content="Nitter")
meta(property="og:locale", content="en_US") meta(property="og:locale", content="en_US")
var siteName = "Nitter"
if time.isSome:
let timeObj = time.get
let timeStr = $timeObj
meta(property="og:article:published_time", content=timeStr)
let formattedTime = timeObj.format("yyyy/MM/dd HH:mm:ss")
siteName = &"Nitter • {formattedTime}"
meta(property="og:site_name", content=siteName)
if banner.len > 0 and not banner.startsWith('#'): if banner.len > 0 and not banner.startsWith('#'):
let bannerUrl = getPicUrl(banner) let bannerUrl = getPicUrl(banner)
link(rel="preload", type="image/png", href=bannerUrl, `as`="image") link(rel="preload", type="image/png", href=bannerUrl, `as`="image")
for url in images: if images.len > 0:
let preloadUrl = if "400x400" in url: getPicUrl(url) for url in images:
else: getSmallPic(url) let preloadUrl = if "400x400" in url: getPicUrl(url)
link(rel="preload", type="image/png", href=preloadUrl, `as`="image") else: getSmallPic(url)
link(rel="preload", type="image/png", href=preloadUrl, `as`="image")
let image = getUrlPrefix(cfg) & getPicUrl(url) let image = getUrlPrefix(cfg) & getPicUrl(url)
meta(property="og:image", content=image) meta(property="og:image", content=image)
if video.len == 0: if video.len == 0:
meta(property="twitter:image:src", content=image) meta(property="twitter:image:src", content=image)
if rss.len > 0: if rss.len > 0:
meta(property="twitter:card", content="summary") meta(property="twitter:card", content="summary")
elif video.len == 0: elif video.len == 0:
meta(property="twitter:card", content="summary_large_image") meta(property="twitter:card", content="summary_large_image")
elif avatar.len > 0:
let avatarUrl = getUrlPrefix(cfg) & getPicUrl(avatar)
meta(property="og:image", content=avatarUrl)
if video.len > 0: if video.len > 0:
meta(property="og:video:url", content=video) meta(property="og:video:url", content=video)
@ -130,7 +146,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
title = author title = author
author = encodeUrl(finalizedDesc) author = encodeUrl(finalizedDesc)
verbatim &"<link rel=\"alternate\" href=\"{getUrlPrefix(cfg)}/oembed.json?type=video&title={title}&user={author}&url={encodeUrl(req.path)}\" type=\"application/json+oembed\" />" verbatim &"<link rel=\"alternate\" href=\"{getUrlPrefix(cfg)}/oembed.json?type=video&provider={encodeUrl(siteName)}&title={title}&user={author}&url={encodeUrl(req.path)}\" type=\"application/json+oembed\" />"
#link(rel="alternate", #link(rel="alternate",
# href=&"{getUrlPrefix(cfg)}/oembed.json?type=video&title={encodeUrl(stripHtml(desc))}&user={encodeUrl(finalizedTitleText)}&url={encodeUrl(req.path)}", # href=&"{getUrlPrefix(cfg)}/oembed.json?type=video&title={encodeUrl(stripHtml(desc))}&user={encodeUrl(finalizedTitleText)}&url={encodeUrl(req.path)}",
# `type`="application/json+oembed") # `type`="application/json+oembed")
@ -142,13 +158,14 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs; proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs;
titleText=""; desc=""; ogTitle=""; rss=""; video=""; titleText=""; desc=""; ogTitle=""; rss=""; video="";
images: seq[string] = @[]; banner=""): string = images: seq[string] = @[]; banner=""; avatar="";
time: Option[DateTime] = none(DateTime)): string =
let canonical = getTwitterLink(req.path, req.params) let canonical = getTwitterLink(req.path, req.params)
let node = buildHtml(html(lang="en")): let node = buildHtml(html(lang="en")):
renderHead(prefs, cfg, req, titleText, desc, video, images, banner, ogTitle, renderHead(prefs, cfg, req, titleText, desc, video, images, banner, ogTitle,
rss, canonical) rss, canonical, avatar, time)
body: body:
renderNavbar(cfg, req, rss, canonical) renderNavbar(cfg, req, rss, canonical)