Skip to content

Commit

Permalink
Implement link previews
Browse files Browse the repository at this point in the history
  • Loading branch information
zedeus committed Aug 7, 2019
1 parent afdbb6a commit ec5f671
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ is on implementing missing features.

- Search (images/videos, hashtags, etc.)
- Custom timeline filter
- Nitter link previews
- More caching (waiting for [moigagoo/norm#19](https://github.com/moigagoo/norm/pull/19))
- Simple account system with customizable feed
- Video support with hls.js
Expand Down
2 changes: 1 addition & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ a:hover {

.replying-to {
color: hsla(240,1%,73%,.9);
margin: -4px 0 4px 0;
margin: -2px 0 4px 0;
}

.status-el .status-content {
Expand Down
6 changes: 6 additions & 0 deletions src/formatters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ proc getUserpic*(userpic: string; style=""): string =
proc getUserpic*(profile: Profile; style=""): string =
getUserPic(profile.userpic, style)

proc getVideoEmbed*(video: Video): string =
&"https://twitter.com/i/videos/{video.videoId}?embed_source=facebook"

proc pageTitle*(profile: Profile): string =
&"{profile.fullname} (@{profile.username})"

proc pageDesc*(profile: Profile): string =
"The latest tweets from " & profile.fullname

proc getTime*(tweet: Tweet): string =
tweet.time.format("d/M/yyyy', ' HH:mm:ss")

Expand Down
14 changes: 12 additions & 2 deletions src/nitter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ proc showSingleTimeline(name, after, agent: string; query: Option[Query]): Futur
return ""

let profileHtml = renderProfile(profile, await timelineFut, await railFut)
return renderMain(profileHtml, title=cfg.title, titleText=pageTitle(profile))
return renderMain(profileHtml, title=cfg.title, titleText=pageTitle(profile), desc=pageDesc(profile))

proc showMultiTimeline(names: seq[string]; after, agent: string; query: Option[Query]): Future[string] {.async.} =
var q = query
Expand Down Expand Up @@ -91,7 +91,17 @@ routes:
resp Http404, showError("Tweet not found", cfg.title)

let title = pageTitle(conversation.tweet.profile)
resp renderMain(renderConversation(conversation), title=cfg.title, titleText=title)
let desc = conversation.tweet.text
let html = renderConversation(conversation)

if conversation.tweet.video.isSome():
let thumb = get(conversation.tweet.video).thumb
let vidUrl = getVideoEmbed(get(conversation.tweet.video))
resp renderMain(html, title=cfg.title, titleText=title, desc=desc,
images = @[thumb], `type`="video", video=vidUrl)
else:
resp renderMain(html, title=cfg.title, titleText=title,
desc=desc, images=conversation.tweet.photos)

get "/pic/@sig/@url":
cond "http" in @"url"
Expand Down
30 changes: 25 additions & 5 deletions src/views/general.nim
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import karax/[karaxdsl, vdom]

import ../utils

const doctype = "<!DOCTYPE html>\n"

proc renderMain*(body: VNode; title="Nitter"; titleText=""): string =
proc renderMain*(body: VNode; title="Nitter"; titleText=""; desc="";
`type`="article"; video=""; images: seq[string] = @[]): string =
let node = buildHtml(html(lang="en")):
head:
if titleText.len > 0:
title: text titleText & " | " & title
else:
title: text title
link(rel="stylesheet", `type`="text/css", href="/style.css")

title:
if titleText.len > 0:
text titleText & " | " & title
else:
text title

meta(name="og:type", content=`type`)
meta(name="og:title", content=titleText)
meta(name="og:description", content=desc)
meta(name="og:site_name", content="Twitter")

for url in images:
meta(name="og:image", content=getSigUrl(url, "pic"))

if video.len > 0:
meta(name="og:video:url", content=video)
meta(name="og:video:secure_url", content=video)
meta(name="og:video:type", content="text/html")
meta(name="og:video:width", content="1200")
meta(name="og:video:height", content="675")

body:
nav(id="nav", class="nav-bar container"):
tdiv(class="inner-nav"):
Expand Down

0 comments on commit ec5f671

Please sign in to comment.