6 module Rakka.Wiki.Interpreter.PageList
10 import Control.Applicative
13 import Data.Monoid.Unicode
14 import qualified Data.Text as T
16 import qualified Data.Time.RFC1123 as RFC1123
18 import Prelude.Unicode
20 import Rakka.SystemConfig
23 import Rakka.Wiki.Interpreter
24 import System.FilePath
25 import Text.HyperEstraier
28 interpreters :: [Interpreter]
29 interpreters = [ recentUpdatesURLInterp
34 recentUpdatesURLInterp :: Interpreter
35 recentUpdatesURLInterp
36 = InlineCommandInterpreter {
37 iciName = "recentUpdatesURL"
39 = \ ctx _ -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
41 uriPath = uriPath baseURI </> "search.html"
42 , uriQuery = '?' : mkQueryString [ ("q" , "[UVSET]")
43 , ("order", "@mdate NUMD")
46 return $ ExternalLink uri (Just "List all pages")
50 -- <div class="recentUpdates">
53 -- <a href="...">...</a>
54 -- <div class="date">...</div>
55 -- <p> <!-- サマリが無ければ存在しない -->
62 recentUpdatesInterp ∷ Interpreter
64 = BlockCommandInterpreter {
65 bciName = "recentUpdates"
67 = \(InterpreterContext {..}) (BlockCommand _ args _) →
68 do let items = fromMaybe 10 $ read ∘ T.unpack <$> lookup "items" args
69 showSummary = fromMaybe True $ parseYesOrNo <$> lookup "showSummary" args
70 onlyEntity = fromMaybe True $ parseYesOrNo <$> lookup "onlyEntity" args
71 onlySummarized = fromMaybe True $ parseYesOrNo <$> lookup "onlySummarized" args
74 $ addAttrCond cond "@type STRNE application/x-rakka-redirection"
76 $ addAttrCond cond "rakka:summary STRNE" -- summary が空でない
77 setPhrase cond "[UVSET]"
78 setOrder cond "@mdate NUMD"
80 result ← searchPages ctxStorage cond
81 mkPageList showSummary (srPages result)
84 mkPageList :: Bool -> [HitPage] -> IO BlockElement
85 mkPageList showSummary pages
86 = do items <- mapM (mkListItem showSummary) pages
87 return (Div [("class", "recentUpdates")]
88 [ Block (List Bullet items) ])
90 mkListItem ∷ Bool → HitPage → IO ListItem
91 mkListItem showSummary page
92 = do lastMod ← utcToLocalZonedTime (hpLastMod page)
93 return ( [ Inline PageLink {
94 linkPage = Just (hpPageName page)
95 , linkFragment = Nothing
98 , Block ( Div [("class", "date")]
99 [Inline (Text (T.pack $ RFC1123.format lastMod))]
103 case (showSummary, hpSummary page) of
105 → [ Block (Paragraph [Text s]) ]