aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Config.hs13
-rw-r--r--src/Main.hs11
2 files changed, 10 insertions, 14 deletions
diff --git a/src/Config.hs b/src/Config.hs
index 799b297..45f9808 100644
--- a/src/Config.hs
+++ b/src/Config.hs
@@ -26,16 +26,19 @@ faviconUrl :: IsString s => IO s
faviconUrl = (fromString . fromMaybe "https://69owo.de/favicon.ico")
<$> lookupEnv "FAVICON_URL"
-makeOpenSearch :: (IsString s, Semigroup s) => s -> IO s
-makeOpenSearch searchUrl = do
+makeOpenSearch :: (IsString s, Semigroup s) => Maybe s -> IO s
+makeOpenSearch defBang = do
favicon <- faviconUrl
+ bp <- getBaseUrl
+ let (searchUrl, name) = case defBang of
+ Nothing -> (bp <> "/#{searchTerms}", "FastBangs")
+ Just b -> (bp <> "/#" <> b <> "#{searchTerms}", "FastBangs (" <> b <> ")")
+
return $ "<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\"\n"
<> " xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">\n"
- <> " <ShortName>Fastbangs</ShortName>\n"
+ <> " <ShortName>" <> name <> "</ShortName>\n"
<> " <Description>Handles search bangs (mostly) locally.</Description>\n"
<> " <InputEncoding>UTF-8</InputEncoding>\n"
<> " <Image width=\"16\" height=\"16\" type=\"image/x-icon\">" <> favicon <> "</Image>\n"
<> " <Url type=\"text/html\" template=\"" <> searchUrl <> "\"/>\n"
- <> " <!--<Url type=\"application/x-suggestions+json\" template=\"[suggestionURL]\"/>-->\n"
- <> " <!--<moz:SearchForm>[https://example.com/search]</moz:SearchForm>-->\n"
<> "</OpenSearchDescription>\n"
diff --git a/src/Main.hs b/src/Main.hs
index ff6823d..b5b35a1 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -15,7 +15,6 @@ import Data.Aeson
import Database.Persist.Sqlite
import Data.Char (isAlphaNum)
import Data.Function ((&))
-import Data.Functor ((<&>))
import Data.Maybe (maybeToList)
import Network.Wai.Handler.Warp hiding (getPort, getHost)
import Yesod
@@ -123,15 +122,9 @@ postSubmitR = do
getOpenSearchR :: Handler TypedContent
getOpenSearchR = do
neverExpires
- baseUrl <- liftIO getBaseUrl
- url <- lookupGetParam "default" <&> \case
- Nothing -> baseUrl <> "/#{searchTerms}"
- Just b -> baseUrl <> "/#" <> b <> "#{searchTerms}"
- liftIO $
- TypedContent "application/opensearchdescription+xml"
- . toContent
- <$> makeOpenSearch url
+ resXml <- liftIO . makeOpenSearch =<< lookupGetParam "default"
+ return $ TypedContent "application/opensearchdescription+xml" $ toContent resXml
postVerdictR :: Bool -> Handler ()
postVerdictR b = do