1
0
mirror of https://github.com/zedeus/nitter.git synced 2025-12-06 03:55:36 -05:00

Add canonical header to help search engines

Fixes #472
This commit is contained in:
Zed
2021-12-30 03:59:11 +01:00
parent 173dd8f016
commit eed4d4033f
3 changed files with 16 additions and 9 deletions

View File

@@ -11,8 +11,7 @@ const
doctype = "<!DOCTYPE html>\n"
lp = readFile("public/lp.svg")
proc renderNavbar*(cfg: Config, rss: string; req: Request): VNode =
let twitterPath = getTwitterLink(req.path, req.params)
proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode =
var path = $(parseUri(req.path) ? filterParams(req.params))
if "/status" in path: path.add "#m"
@@ -27,14 +26,14 @@ proc renderNavbar*(cfg: Config, rss: string; req: Request): VNode =
icon "search", title="Search", href="/search"
if cfg.enableRss and rss.len > 0:
icon "rss-feed", title="RSS Feed", href=rss
icon "bird", title="Open in Twitter", href=twitterPath
icon "bird", title="Open in Twitter", href=canonical
a(href="https://liberapay.com/zedeus"): verbatim lp
icon "info", title="About", href="/about"
iconReferer "cog", "/settings", path, title="Preferences"
proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
images: seq[string] = @[]; banner=""; ogTitle=""; theme="";
rss=""): VNode =
rss=""; canonical=""): VNode =
let ogType =
if video.len > 0: "video"
elif rss.len > 0: "object"
@@ -58,6 +57,9 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
link(rel="search", type="application/opensearchdescription+xml", title=cfg.title,
href=opensearchUrl)
if canonical.len > 0:
link(rel="canonical", href=canonical)
if cfg.enableRss and rss.len > 0:
link(rel="alternate", type="application/rss+xml", href=rss, title="RSS feed")
@@ -117,11 +119,14 @@ proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs;
if "theme" in req.params:
theme = toLowerAscii(req.params["theme"]).replace(" ", "_")
let canonical = getTwitterLink(req.path, req.params)
let node = buildHtml(html(lang="en")):
renderHead(prefs, cfg, titleText, desc, video, images, banner, ogTitle, theme, rss)
renderHead(prefs, cfg, titleText, desc, video, images, banner, ogTitle,
theme, rss, canonical)
body:
renderNavbar(cfg, rss, req)
renderNavbar(cfg, req, rss, canonical)
tdiv(class="container"):
body