1 module Rakka.Wiki.Interpreter.PageList
9 import Network.HTTP.Lucu.RFC1123DateTime
13 import Rakka.Wiki.Interpreter
14 import Text.HyperEstraier
17 interpreters :: [Interpreter]
18 interpreters = [ recentUpdatesInterp ]
21 -- <div class="recentUpdates">
24 -- <a href="...">...</a>
25 -- <div class="date">...</div>
26 -- <p> <!-- サマリが無ければ存在しない -->
33 recentUpdatesInterp :: Interpreter
35 = BlockCommandInterpreter {
36 bciName = "recentUpdates"
38 = \ ctx (BlockCommand _ args _)
39 -> do let items = fromMaybe 10 $ fmap read $ lookup "items" args
40 showSummary = fromMaybe True $ fmap parseYesOrNo $ lookup "showSummary" args
41 onlyEntity = fromMaybe True $ fmap parseYesOrNo $ lookup "onlyEntity" args
42 onlySummarized = fromMaybe True $ fmap parseYesOrNo $ lookup "onlySummarized" args
47 $ addAttrCond cond "@type STRNE application/x-rakka-redirection"
49 $ addAttrCond cond "rakka:summary STRNE" -- summary が空でない
50 setPhrase cond "[UVSET]"
51 setOrder cond "@mdate NUMD"
54 result <- searchPages sto cond
55 mkPageList showSummary (srPages result)
58 mkPageList :: Bool -> [HitPage] -> IO BlockElement
59 mkPageList showSummary pages
60 = do items <- mapM (mkListItem showSummary) pages
61 return (Div [("class", "recentUpdates")]
62 [ Block (List Bullet items) ])
64 mkListItem :: Bool -> HitPage -> IO ListItem
65 mkListItem showSummary page
66 = do lastMod <- utcToLocalZonedTime (hpLastMod page)
67 return ( [ Inline ( PageLink {
68 linkPage = Just (hpPageName page)
69 , linkFragment = Nothing
73 , Block ( Div [("class", "date")]
74 [Inline (Text (formatRFC1123DateTime lastMod))]
78 case (showSummary, hpSummary page) of
80 -> [ Block (Paragraph [Text s]) ]