aboutsummaryrefslogtreecommitdiff
path: root/site.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2023-06-18 14:10:59 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2023-06-18 14:36:41 +0200
commit15a0543ab38f1fcbc29dc058b8d02fcfe376ee8f (patch)
treeeeb57cbcd9ab22fdab0c125d66e985f70a6ab2f1 /site.hs
parentdb5847e1ec6338e6fc298415fdb25fa8d1740bc6 (diff)
downloadreploy-15a0543ab38f1fcbc29dc058b8d02fcfe376ee8f.tar.gz
reploy-15a0543ab38f1fcbc29dc058b8d02fcfe376ee8f.tar.bz2
proper index
Diffstat (limited to 'site.hs')
-rw-r--r--site.hs29
1 files changed, 18 insertions, 11 deletions
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