1 module Rakka.Wiki.Interpreter.PageList
9 import Network.HTTP.Lucu.RFC1123DateTime
14 import Rakka.Wiki.Interpreter
15 import Text.HyperEstraier
18 interpreters :: [Interpreter]
19 interpreters = [ recentUpdatesInterp ]
22 -- <div class="recentUpdates">
25 -- <a href="...">...</a>
26 -- <div class="date">...</div>
27 -- <p> <!-- サマリが無ければ存在しない -->
34 recentUpdatesInterp :: Interpreter
36 = BlockCommandInterpreter {
37 bciName = "recentUpdates"
39 = \ ctx (BlockCommand _ args _)
40 -> do let items = fromMaybe 10 $ fmap read $ lookup "items" args
41 showSummary = fromMaybe True $ fmap parseYesOrNo $ lookup "showSummary" args
42 onlyEntity = fromMaybe True $ fmap parseYesOrNo $ lookup "onlyEntity" args
43 onlySummarized = fromMaybe True $ fmap parseYesOrNo $ lookup "onlySummarized" args
48 $ addAttrCond cond "@type STRNE application/x-rakka-redirection"
50 $ addAttrCond cond "rakka:summary STRNE" -- summary が空でない
51 setPhrase cond "[UVSET]"
52 setOrder cond "@mdate NUMD"
55 result <- searchPages sto cond
56 pages <- mapM (getPageByHP sto) (srPages result)
58 mkPageList showSummary pages
61 getPageByHP :: Storage -> HitPage -> IO Page
63 = getPage sto (hpPageName hp) (Just (hpPageRev hp)) >>= return . fromJust
65 mkPageList :: Bool -> [Page] -> IO BlockElement
66 mkPageList showSummary pages
67 = do items <- mapM (mkListItem showSummary) pages
68 return (Div [("class", "recentUpdates")]
69 [ Block (List Bullet items) ])
71 mkListItem :: Bool -> Page -> IO ListItem
72 mkListItem showSummary page
73 = do lastMod <- utcToLocalZonedTime (entityLastMod page)
74 return ( [ Inline ( PageLink {
75 linkPage = Just (pageName page)
76 , linkFragment = Nothing
80 , Block ( Div [("class", "date")]
81 [Inline (Text (formatRFC1123DateTime lastMod))]
85 case (showSummary, entitySummary page) of
87 -> [ Block (Paragraph [Text s]) ]