Skip to content

Commit

Permalink
Various small fixes (#240)
Browse files Browse the repository at this point in the history
* Case insensitive search

* Render comments in search results, fix API
  • Loading branch information
paf31 authored Aug 13, 2016
1 parent a49303c commit b29fb85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Foundation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ instance PathPiece VerificationKey where
data SearchResult = SearchResult
{ hrPkgName :: PackageName
, hrPkgVersion :: Version
, hrDetails :: String
, hrComments :: String
, hrInfo :: SearchResultInfo
}
deriving (Show, Eq, Generic)
Expand Down
6 changes: 3 additions & 3 deletions src/Handler/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ createDatabase = do
return . fromListWithDuplicates $ do
D.Package{..} <- pkgs
let packageEntry =
( fromString (tryStripPrefix "purescript-" (runPackageName (bowerName pkgMeta)))
( fromString (tryStripPrefix "purescript-" (toLower (runPackageName (bowerName pkgMeta))))
, SearchResult (bowerName pkgMeta)
pkgVersion
(fromMaybe "" (bowerDescription pkgMeta))
Expand All @@ -61,7 +61,7 @@ createDatabase = do
packageEntry : do
D.Module{..} <- pkgModules
let moduleEntry =
( fromString (P.runModuleName modName)
( fromString (toLower (P.runModuleName modName))
, SearchResult (bowerName pkgMeta)
pkgVersion
(fromMaybe "" modComments)
Expand All @@ -74,7 +74,7 @@ createDatabase = do
D.ValueDeclaration{} -> Value
D.AliasDeclaration{} -> Value
_ -> Type
return ( fromString declTitle
return ( fromString (toLower declTitle)
, SearchResult (bowerName pkgMeta)
pkgVersion
(fromMaybe "" declComments)
Expand Down
15 changes: 13 additions & 2 deletions src/Handler/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import qualified Web.Bower.PackageMeta as Bower
import Model.DocsAsHtml (makeFragment)
import TemplateHelpers (getFragmentRender)

import Cheapskate (allowRawHtml, markdown)
import qualified Text.Blaze as Blaze
import qualified Text.Blaze.Renderer.Text as Blaze

getSearchR :: Handler TypedContent
getSearchR = do
mquery <- (map . map) unpack $ lookupGetParam "q"
case mquery of
Nothing -> redirect HomeR
Just query -> do
results <- searchForName query
results <- searchForName (toLower query)
selectRep $ do
provideRep (htmlOutput query results)
provideRep (jsonOutput results)
Expand All @@ -34,10 +38,12 @@ getSearchR = do
searchResultToJSON :: SearchResult -> Handler Value
searchResultToJSON result@SearchResult{..} = do
url <- getFragmentRender <*> pure (routeResult result)
let html = renderComments hrComments
return $
object [ "package" .= hrPkgName
, "version" .= showVersion hrPkgVersion
, "details" .= hrDetails
, "markup" .= Blaze.renderMarkup html
, "text" .= Blaze.renderMarkup (Blaze.contents html)
, "info" .= toJSON hrInfo
, "url" .= url
]
Expand Down Expand Up @@ -65,3 +71,8 @@ searchForName :: String -> Handler [SearchResult]
searchForName query = do
db <- atomically . readTVar =<< (appDatabase <$> getYesod)
return (take 50 (concat (elems (submap (fromString query) db))))

renderComments :: String -> Html
renderComments = Blaze.toMarkup . markdown opts . pack
where
opts = def { allowRawHtml = False }
2 changes: 1 addition & 1 deletion templates/search.hamlet
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<p>#{name}

<p>
<small>#{hrDetails r}
<small>#{renderComments $ hrComments r}

$case hrInfo r
$of PackageResult
Expand Down

0 comments on commit b29fb85

Please sign in to comment.