Skip to content

Commit

Permalink
Implements OpenSearch support, closes #107
Browse files Browse the repository at this point in the history
  • Loading branch information
setenforce0 committed Jan 3, 2020
1 parent ee43d8c commit 8bffb61
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/routes/search.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import router_utils
import ".."/[query, types, api, agents]
import ../views/[general, search]

include "../views/opensearch.nimf"

export search

proc createSearchRouter*(cfg: Config) =
Expand Down Expand Up @@ -33,3 +35,12 @@ proc createSearchRouter*(cfg: Config) =

get "/hashtag/@hash":
redirect("/search?q=" & encodeUrl("#" & @"hash"))

get "/opensearch":
var url = ""
if cfg.useHttps:
url = "https://" & cfg.hostname & "/search?q="
else:
url = "https://" & cfg.hostname & "/search?q="
resp Http200, {"Content-Type": "application/opensearchdescription+xml"},
generateOpenSearchXML(cfg.title, cfg.hostname, url)
2 changes: 2 additions & 0 deletions src/views/general.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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="manifest", href="/site.webmanifest")
link(rel="mask-icon", href="/safari-pinned-tab.svg", color="#ff6c60")
link(rel="search", type="application/opensearchdescription+xml", title=cfg.title,
href="https://localhost:8080/opensearch")

if prefs.hlsPlayback:
script(src="/js/hls.light.min.js")
Expand Down
12 changes: 12 additions & 0 deletions src/views/opensearch.nimf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#? stdtmpl(subsChar = '$', metaChar = '#')
#proc generateOpenSearchXML*(name, hostname, url: string): string =
# result = ""
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="https://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="https://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

0 comments on commit 8bffb61

Please sign in to comment.