6 module Rakka.Wiki.Interpreter.PageList
10 import Control.Applicative
12 import qualified Data.ByteString.Char8 as C8
14 import Data.Monoid.Unicode
15 import qualified Data.Text as T
17 import qualified Data.Time.RFC1123 as RFC1123
19 import Prelude.Unicode
21 import Rakka.SystemConfig
24 import Rakka.Wiki.Interpreter
25 import System.FilePath
26 import Text.HyperEstraier
29 interpreters :: [Interpreter]
30 interpreters = [ recentUpdatesURLInterp
35 recentUpdatesURLInterp :: Interpreter
36 recentUpdatesURLInterp
37 = InlineCommandInterpreter {
38 iciName = "recentUpdatesURL"
40 = \ ctx _ -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
42 uriPath = uriPath baseURI </> "search.html"
43 , uriQuery = '?' : C8.unpack (mkQueryString [ ("q" , "[UVSET]")
44 , ("order", "@mdate NUMD")
47 return $ ExternalLink uri (Just "List all pages")
51 -- <div class="recentUpdates">
54 -- <a href="...">...</a>
55 -- <div class="date">...</div>
56 -- <p> <!-- サマリが無ければ存在しない -->
63 recentUpdatesInterp ∷ Interpreter
65 = BlockCommandInterpreter {
66 bciName = "recentUpdates"
68 = \(InterpreterContext {..}) (BlockCommand _ args _) →
69 do let items = fromMaybe 10 $ read ∘ T.unpack <$> lookup "items" args
70 showSummary = fromMaybe True $ parseYesOrNo <$> lookup "showSummary" args
71 onlyEntity = fromMaybe True $ parseYesOrNo <$> lookup "onlyEntity" args
72 onlySummarized = fromMaybe True $ parseYesOrNo <$> lookup "onlySummarized" args
75 $ addAttrCond cond "@type STRNE application/x-rakka-redirection"
77 $ addAttrCond cond "rakka:summary STRNE" -- summary が空でない
78 setPhrase cond "[UVSET]"
79 setOrder cond "@mdate NUMD"
81 result ← searchPages ctxStorage cond
82 mkPageList showSummary (srPages result)
85 mkPageList :: Bool -> [HitPage] -> IO BlockElement
86 mkPageList showSummary pages
87 = do items <- mapM (mkListItem showSummary) pages
88 return (Div [("class", "recentUpdates")]
89 [ Block (List Bullet items) ])
91 mkListItem ∷ Bool → HitPage → IO ListItem
92 mkListItem showSummary page
93 = do lastMod ← utcToLocalZonedTime (hpLastMod page)
94 return ( [ Inline PageLink {
95 linkPage = Just (hpPageName page)
96 , linkFragment = Nothing
99 , Block ( Div [("class", "date")]
100 [Inline (Text (T.pack $ RFC1123.format lastMod))]
104 case (showSummary, hpSummary page) of
106 → [ Block (Paragraph [Text s]) ]