X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FPageList.hs;h=cffd93806f20c50b490dec6af1a9ac5596198a72;hb=b4c0033f297c28d95ad9298b489126331224bc42;hp=234ce7d007498d9f3b66893a2c02ae69b3d46bca;hpb=7a4f13a3d483c950743e1ced001ade4406d239d3;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/PageList.hs b/Rakka/Wiki/Interpreter/PageList.hs index 234ce7d..cffd938 100644 --- a/Rakka/Wiki/Interpreter/PageList.hs +++ b/Rakka/Wiki/Interpreter/PageList.hs @@ -3,11 +3,13 @@ module Rakka.Wiki.Interpreter.PageList ) where +import Control.Monad import Data.Maybe import Data.Time import Network.HTTP.Lucu.RFC1123DateTime import Rakka.Page import Rakka.Storage +import Rakka.Utils import Rakka.Wiki import Rakka.Wiki.Interpreter import Text.HyperEstraier @@ -35,33 +37,40 @@ recentUpdatesInterp bciName = "recentUpdates" , bciInterpret = \ ctx (BlockCommand _ args _) - -> do let items = fromMaybe 10 $ fmap read $ lookup "items" args - sto = ctxStorage ctx + -> do let items = fromMaybe 10 $ fmap read $ lookup "items" args + showSummary = fromMaybe True $ fmap parseYesOrNo $ lookup "showSummary" args + onlyEntity = fromMaybe True $ fmap parseYesOrNo $ lookup "onlyEntity" args + onlySummarized = fromMaybe True $ fmap parseYesOrNo $ lookup "onlySummarized" args + sto = ctxStorage ctx cond <- newCondition - setPhrase cond "[UVSET]" - addAttrCond cond "rakka:isBoring STREQ no" - addAttrCond cond "rakka:summary STRNE" -- summary が空でない - setOrder cond "@mdate NUMD" - setMax cond items + when onlyEntity + $ addAttrCond cond "@type STRNE application/x-rakka-redirection" + when onlySummarized + $ addAttrCond cond "rakka:summary STRNE" -- summary が空でない + setPhrase cond "[UVSET]" + setOrder cond "@mdate NUMD" + setMax cond items result <- searchPages sto cond - pages <- mapM ( \ (name, rev) - -> getPage sto name (Just rev) >>= return . fromJust - ) result + pages <- mapM (getPageByHP sto) (srPages result) - mkPageList pages + mkPageList showSummary pages } where - mkPageList :: [Page] -> IO BlockElement - mkPageList pages - = do items <- mapM mkListItem pages + getPageByHP :: Storage -> HitPage -> IO Page + getPageByHP sto hp + = getPage sto (hpPageName hp) (Just (hpPageRev hp)) >>= return . fromJust + + mkPageList :: Bool -> [Page] -> IO BlockElement + mkPageList showSummary pages + = do items <- mapM (mkListItem showSummary) pages return (Div [("class", "recentUpdates")] [ Block (List Bullet items) ]) - mkListItem :: Page -> IO ListItem - mkListItem page - = do lastMod <- utcToLocalZonedTime (pageLastMod page) + mkListItem :: Bool -> Page -> IO ListItem + mkListItem showSummary page + = do lastMod <- utcToLocalZonedTime (entityLastMod page) return ( [ Inline ( PageLink { linkPage = Just (pageName page) , linkFragment = Nothing @@ -73,7 +82,8 @@ recentUpdatesInterp ) ] ++ - case pageSummary page of - Just s -> [ Block (Paragraph [Text s]) ] - Nothing -> [] + case (showSummary, entitySummary page) of + (True, Just s) + -> [ Block (Paragraph [Text s]) ] + _ -> [] )