X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FPageList.hs;h=fd4d364ebde2ad6af3c7ae37f9bdfb72c935ad1d;hb=9d86882fe1630c844e11cf2cf760110c04ea10d4;hp=1b433b87faf486637d92fbaffce8aa1e2e075140;hpb=b4a3d2cf3854b10d923cb4c546bf1fe32b021a68;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/PageList.hs b/Rakka/Wiki/Interpreter/PageList.hs index 1b433b8..fd4d364 100644 --- a/Rakka/Wiki/Interpreter/PageList.hs +++ b/Rakka/Wiki/Interpreter/PageList.hs @@ -3,18 +3,40 @@ module Rakka.Wiki.Interpreter.PageList ) where +import Control.Monad import Data.Maybe import Data.Time import Network.HTTP.Lucu.RFC1123DateTime -import Rakka.Page +import Network.URI import Rakka.Storage +import Rakka.SystemConfig +import Rakka.Utils import Rakka.Wiki import Rakka.Wiki.Interpreter +import System.FilePath import Text.HyperEstraier interpreters :: [Interpreter] -interpreters = [ recentUpdatesInterp ] +interpreters = [ recentUpdatesURLInterp + , recentUpdatesInterp + ] + + +recentUpdatesURLInterp :: Interpreter +recentUpdatesURLInterp + = InlineCommandInterpreter { + iciName = "recentUpdatesURL" + , iciInterpret + = \ ctx _ -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx) + let uri = baseURI { + uriPath = uriPath baseURI "search.html" + , uriQuery = '?' : mkQueryString [ ("q" , "[UVSET]") + , ("order", "@mdate NUMD") + ] + } + return $ ExternalLink uri (Just "List all pages") + } --
@@ -35,35 +57,36 @@ 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 - - mkPageList pages + mkPageList showSummary (srPages result) } where - mkPageList :: [Page] -> IO BlockElement - mkPageList pages - = do items <- mapM mkListItem pages + mkPageList :: Bool -> [HitPage] -> 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 (entityLastMod page) + mkListItem :: Bool -> HitPage -> IO ListItem + mkListItem showSummary page + = do lastMod <- utcToLocalZonedTime (hpLastMod page) return ( [ Inline ( PageLink { - linkPage = Just (pageName page) + linkPage = Just (hpPageName page) , linkFragment = Nothing , linkText = Nothing } @@ -73,7 +96,8 @@ recentUpdatesInterp ) ] ++ - case entitySummary page of - Just s -> [ Block (Paragraph [Text s]) ] - Nothing -> [] + case (showSummary, hpSummary page) of + (True, Just s) + -> [ Block (Paragraph [Text s]) ] + _ -> [] )