From 15a0543ab38f1fcbc29dc058b8d02fcfe376ee8f Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Sun, 18 Jun 2023 14:10:59 +0200 Subject: proper index --- site.hs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'site.hs') diff --git a/site.hs b/site.hs index c5ff809..6c6e895 100644 --- a/site.hs +++ b/site.hs @@ -134,7 +134,8 @@ rootUrl fp = ( unAbsolute fp) <$> use urlBase -- | Process a single link pointing out from a page. processLink :: FilePath -> FilePath -> Site String processLink base l = - if any (l `hasUriScheme`) ["http", "https", "ftp", "mailto"] || take 1 l == "#" + if any (l `hasUriScheme`) ["http", "https", "ftp", "mailto"] || take 1 l == + "#" then pure l else if isAbsolute l then rootUrl l @@ -346,20 +347,26 @@ renderTags :: Site () renderTags = use (htags . to M.keys) >>= traverse_ renderTag -- | Transform one mounted PageInfo to the base search data -mkSearchData :: FilePath -> PageInfo -> Site Y.Value +mkSearchData :: FilePath -> PageInfo -> Site [Y.Value] mkSearchData mount pi = do link <- rootUrl mount text <- io . runIOorExplode $ writePlain plainWriteOpts (pi ^. pageDoc) let title = pi ^? pageMeta . key "title" . _String -- TODO: unify retrieval of tags - let tags = sort $ pi ^.. pageMeta . key "tags" . values . _String . to T.unpack - pure $ - Y.object - [ ("link", fromString link) - , ("title", maybe (fromString mount) Y.String title) - , ("tags", Y.array $ map (Y.array . map fromString . splitDirectories) tags) - , ("text", Y.String text) - ] + let tags = + sort $ pi ^.. pageMeta . key "tags" . values . _String . to T.unpack + if pi ^? pageMeta . key "search" . _Bool == Just False -- `off` gets parsed as bool + then pure [] + else pure $ + [ Y.object + [ ("link", fromString link) + , ("title", maybe (fromString mount) Y.String title) + , ( "tags" + , Y.array $ + map (Y.array . map fromString . splitDirectories) tags) + , ("text", Y.String text) + ] + ] -- | Collect all pages' search data to the file renderSearchData :: Site () @@ -369,7 +376,7 @@ renderSearchData = use searchDataOut >>= traverse_ go ps <- use (pages . to M.assocs) >>= traverse (uncurry mkSearchData) io $ do putStrLn $ "S -> " ++ out - AE.encodeFile out $ Y.array ps + AE.encodeFile out $ Y.array (concat ps) -- | Build the whole site. main = do -- cgit v1.2.3