Implements OpenSearch support, closes #107

This commit is contained in:
Kadin Buckton 2020-01-03 09:47:57 -05:00
parent ee43d8cfb1
commit 8bffb61e68
3 changed files with 25 additions and 0 deletions

View file

@ -6,6 +6,8 @@ import router_utils
import ".."/[query, types, api, agents] import ".."/[query, types, api, agents]
import ../views/[general, search] import ../views/[general, search]
include "../views/opensearch.nimf"
export search export search
proc createSearchRouter*(cfg: Config) = proc createSearchRouter*(cfg: Config) =
@ -33,3 +35,12 @@ proc createSearchRouter*(cfg: Config) =
get "/hashtag/@hash": get "/hashtag/@hash":
redirect("/search?q=" & encodeUrl("#" & @"hash")) redirect("/search?q=" & encodeUrl("#" & @"hash"))
get "/opensearch":
var url = ""
if cfg.useHttps:
url = "https://" & cfg.hostname & "/search?q="
else:
url = "http://" & cfg.hostname & "/search?q="
resp Http200, {"Content-Type": "application/opensearchdescription+xml"},
generateOpenSearchXML(cfg.title, cfg.hostname, url)

View file

@ -43,6 +43,8 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
link(rel="icon", type="image/png", sizes="16x16", href="/favicon-16x16.png") link(rel="icon", type="image/png", sizes="16x16", href="/favicon-16x16.png")
link(rel="manifest", href="/site.webmanifest") link(rel="manifest", href="/site.webmanifest")
link(rel="mask-icon", href="/safari-pinned-tab.svg", color="#ff6c60") link(rel="mask-icon", href="/safari-pinned-tab.svg", color="#ff6c60")
link(rel="search", type="application/opensearchdescription+xml", title=cfg.title,
href="http://localhost:8080/opensearch")
if prefs.hlsPlayback: if prefs.hlsPlayback:
script(src="/js/hls.light.min.js") script(src="/js/hls.light.min.js")

12
src/views/opensearch.nimf Normal file
View file

@ -0,0 +1,12 @@
#? stdtmpl(subsChar = '$', metaChar = '#')
#proc generateOpenSearchXML*(name, hostname, url: string): string =
# result = ""
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>${name}</ShortName>
<Description>Twitter search via ${hostname}</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" template="${url}{searchTerms}" />
</OpenSearchDescription>
#end proc