From 38565e2e1f28e027bf1a8af7ce39c7e2523a50f6 Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 24 Jun 2019 22:40:48 +0200 Subject: [PATCH] Add dynamic page title --- README.md | 2 +- src/formatters.nim | 6 ++++++ src/nitter.nim | 12 +++++++----- src/views/general.nim | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dca76e1..7d5512a 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Inspired by the [invidio.us](https://github.com/omarroth/invidious) project. - All requests go through the backend, client never talks to Twitter - Prevents Twitter from tracking your IP or JavaScript fingerprint - Unofficial API (no rate limits or developer account required) -- Lightweight (for [@nim_lang](https://twitter.com/nim_lang), 32KB vs 552KB from twitter.com) - AGPLv3 licensed, no proprietary instances permitted - Dark theme +- Lightweight (for [@nim_lang](https://twitter.com/nim_lang), 36KB vs 580KB from twitter.com) ## Installation diff --git a/src/formatters.nim b/src/formatters.nim index e14c117..639f6c0 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -79,3 +79,9 @@ proc linkUser*(profile: Profile; class=""): string = result &= span("✔", class="verified-icon", title="Verified account") if not username and profile.protected: result &= span("🔒", class="protected-icon", title="Protected account") + +proc pageTitle*(profile: Profile): string = + &"{profile.fullname} (@{profile.username}) | Nitter" + +proc pageTitle*(page: string): string = + &"{page} | Nitter" diff --git a/src/nitter.nim b/src/nitter.nim index a7be473..d9200c9 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -1,7 +1,7 @@ -import asyncdispatch, asyncfile, httpclient, strutils, uri, os +import asyncdispatch, asyncfile, httpclient, strutils, strformat, uri, os import jester -import api, utils, types, cache +import api, utils, types, cache, formatters import views/[user, general, conversation] const cacheDir {.strdefine.} = "/tmp/nitter" @@ -16,11 +16,12 @@ proc showTimeline(name: string; num=""): Future[string] {.async.} = if profile.username.len == 0: return "" - return renderMain(renderProfile(profile, await tweetsFut, num.len == 0)) + let profileHtml = renderProfile(profile, await tweetsFut, num.len == 0) + return renderMain(profileHtml, title=pageTitle(profile)) routes: get "/": - resp renderMain(renderSearchPanel()) + resp renderMain(renderSearchPanel(), title=pageTitle("Search")) post "/search": if @"query".len == 0: @@ -44,7 +45,8 @@ routes: if conversation.tweet.id.len == 0: resp Http404, showError("Tweet not found") - resp renderMain(renderConversation(conversation)) + let title = pageTitle(conversation.tweet.profile) + resp renderMain(renderConversation(conversation), title=title) get "/pic/@sig/@url": cond "http" in @"url" diff --git a/src/views/general.nim b/src/views/general.nim index 22de8b3..9ccf7f3 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -2,11 +2,11 @@ #import user #import xmltree # -#proc renderMain*(body: string): string = +#proc renderMain*(body: string; title="Nitter"): string = - Nitter + ${xmltree.escape(title)} @@ -46,5 +46,5 @@ #end proc # #proc showError*(error: string): string = -${renderMain(renderError(error))} +${renderMain(renderError(error), title="Error | Nitter")} #end proc