X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FPageList.hs;h=d94f67ea1545a597b511c8f116e8fac5ebe37c44;hb=42f51754dea02201aececaacbf194d714cd58aaf;hp=8631c8b4bae98d3929b98bbe369ce69925ed429a;hpb=4abf7df08bf0a614ea8179e8d1d69a17aac4f197;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/PageList.hs b/Rakka/Wiki/Interpreter/PageList.hs index 8631c8b..d94f67e 100644 --- a/Rakka/Wiki/Interpreter/PageList.hs +++ b/Rakka/Wiki/Interpreter/PageList.hs @@ -1,21 +1,50 @@ +{-# LANGUAGE + OverloadedStrings + , RecordWildCards + , UnicodeSyntax + #-} module Rakka.Wiki.Interpreter.PageList ( interpreters ) where - -import Control.Monad -import Data.Maybe +import Control.Applicative +import Control.Monad +import Data.Maybe +import Data.Monoid.Unicode +import qualified Data.Text as T import Data.Time -import Network.HTTP.Lucu.RFC1123DateTime +import qualified Data.Time.RFC1123 as RFC1123 +import Network.URI +import Prelude.Unicode 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") + } --
@@ -30,29 +59,26 @@ interpreters = [ recentUpdatesInterp ] -- ... -- --
-recentUpdatesInterp :: Interpreter +recentUpdatesInterp ∷ Interpreter recentUpdatesInterp = BlockCommandInterpreter { bciName = "recentUpdates" , bciInterpret - = \ ctx (BlockCommand _ args _) - -> 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 - 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 - mkPageList showSummary (srPages result) + = \(InterpreterContext {..}) (BlockCommand _ args _) → + do let items = fromMaybe 10 $ read ∘ T.unpack <$> lookup "items" args + showSummary = fromMaybe True $ parseYesOrNo <$> lookup "showSummary" args + onlyEntity = fromMaybe True $ parseYesOrNo <$> lookup "onlyEntity" args + onlySummarized = fromMaybe True $ parseYesOrNo <$> lookup "onlySummarized" args + cond ← newCondition + 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 ctxStorage cond + mkPageList showSummary (srPages result) } where mkPageList :: Bool -> [HitPage] -> IO BlockElement @@ -61,22 +87,21 @@ recentUpdatesInterp return (Div [("class", "recentUpdates")] [ Block (List Bullet items) ]) - mkListItem :: Bool -> HitPage -> IO ListItem + mkListItem ∷ Bool → HitPage → IO ListItem mkListItem showSummary page - = do lastMod <- utcToLocalZonedTime (hpLastMod page) - return ( [ Inline ( PageLink { - linkPage = Just (hpPageName page) - , linkFragment = Nothing - , linkText = Nothing - } - ) + = do lastMod ← utcToLocalZonedTime (hpLastMod page) + return ( [ Inline PageLink { + linkPage = Just (hpPageName page) + , linkFragment = Nothing + , linkText = Nothing + } , Block ( Div [("class", "date")] - [Inline (Text (formatRFC1123DateTime lastMod))] + [Inline (Text (T.pack $ RFC1123.format lastMod))] ) ] - ++ + ⊕ case (showSummary, hpSummary page) of (True, Just s) - -> [ Block (Paragraph [Text s]) ] - _ -> [] + → [ Block (Paragraph [Text s]) ] + _ → [] )