, runXmlA
, getEntityType
, outputXmlPage
+ , outputXmlPage'
, getUserID
)
where
where
extMap :: [(String, MIMEType)]
extMap = [ ("html", read "application/xhtml+xml")
+ , ( "rdf", read "application/rdf+xml" )
, ( "xml", read "text/xml" )
]
-outputXmlPage :: XmlTree -> IOSArrow XmlTree XmlTree -> Resource ()
-outputXmlPage tree toXHTML
+outputXmlPage :: XmlTree -> [(MIMEType, IOSArrow XmlTree XmlTree)] -> Resource ()
+outputXmlPage tree formatters
= do mType <- getEntityType
setContentType mType
- let formatter = case mType of
- MIMEType "application" "xhtml+xml" _ -> toXHTML
- MIMEType "text" "xml" _ -> this
- _ -> undefined
+ let formatter = case lookup mType formatters of
+ Just f -> f
+ Nothing -> this
[resultStr] <- liftIO $ runX ( setErrorMsgHandler False fail
>>>
constA tree
output resultStr
+outputXmlPage' :: XmlTree -> IOSArrow XmlTree XmlTree -> Resource ()
+outputXmlPage' tree toXHTML
+ = outputXmlPage tree [(MIMEType "application" "xhtml+xml" [], toXHTML)]
+
+
getUserID :: Environment -> Resource (Maybe String)
getUserID env
= do auth <- getAuthorization
import Control.Monad.Trans
import Data.Char
import Data.Maybe
+import Data.Time
import Network.HTTP.Lucu
import Network.HTTP.Lucu.Utils
import Network.URI hiding (path)
import Rakka.Storage
import Rakka.SystemConfig
import Rakka.Utils
+import Rakka.W3CDateTime
import Rakka.Wiki.Engine
import System.FilePath
import Text.XML.HXT.Arrow.Namespace
= proc redir
-> returnA -< do mType <- getEntityType
case mType of
- MIMEType "application" "xhtml+xml" _
- -> do BaseURI baseURI <- getSysConf (envSysConf env)
- let uri = mkPageFragmentURI
- baseURI
- (redirDest redir)
- ("Redirect:" ++ redirName redir)
- redirect Found uri
-
MIMEType "text" "xml" _
-> do setContentType mType
[resultStr] <- liftIO $ runX ( setErrorMsgHandler False fail
)
output resultStr
- _ -> fail ("internal error: getEntityType returned " ++ show mType)
+ _ -> do BaseURI baseURI <- getSysConf (envSysConf env)
+ let uri = mkPageFragmentURI
+ baseURI
+ (redirDest redir)
+ ("Redirect:" ++ redirName redir)
+ redirect Found uri
handleGetEntity :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a Page (Resource ())
0 -> foundTimeStamp (entityLastMod page) -- 0 はデフォルトページ
rev -> foundEntity (strongETag $ show rev) (entityLastMod page)
- outputXmlPage tree (entityToXHTML env)
+ outputXmlPage tree [ (MIMEType "application" "xhtml+xml" [], entityToXHTML env)
+ , (MIMEType "application" "rdf+xml" [], entityToRSS env)
+ ]
entityToXHTML :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a XmlTree XmlTree
) ) -<< page
+entityToRSS :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a XmlTree XmlTree
+entityToRSS env
+ = proc page
+ -> do SiteName siteName <- getSysConfA (envSysConf env) -< ()
+ BaseURI baseURI <- getSysConfA (envSysConf env) -< ()
+
+ name <- (getXPathTreesInDoc "/page/@name/text()" >>> getText) -< page
+ summary <- maybeA (getXPathTreesInDoc "/page/summary/text()" >>> getText) -< page
+ pages <- makePageLinkList (envStorage env) (envSysConf env) (envInterpTable env) -< page
+
+ ( eelem "/"
+ += ( eelem "rdf:RDF"
+ += sattr "xmlns" "http://purl.org/rss/1.0/"
+ += sattr "xmlns:rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ += sattr "xmlns:dc" "http://purl.org/dc/elements/1.1/"
+ += sattr "xmlns:trackback" "http://madskills.com/public/xml/rss/module/trackback/"
+ += ( eelem "channel"
+ += sattr "rdf:about" (uriToString id (mkRDFURI baseURI name) "")
+ += ( eelem "title"
+ += txt siteName
+ += txt " - "
+ += getXPathTreesInDoc "/page/@name/text()"
+ )
+ += ( eelem "link"
+ += txt (uriToString id baseURI "")
+ )
+ += ( eelem "description"
+ += txt (case summary of
+ Nothing -> "RSS Feed for " ++ siteName
+ Just s -> s)
+ )
+ += ( eelem "items"
+ += ( eelem "rdf:Seq"
+ += ( constL pages
+ >>>
+ eelem "rdf:li"
+ += attr "resource" (arr (mkPageURIStr baseURI) >>> mkText)
+ )
+ )
+ )
+ )
+ += ( constL pages
+ >>>
+ arr (\ n -> (n, Nothing))
+ >>>
+ getPageA (envStorage env)
+ >>>
+ arr fromJust
+ >>>
+ eelem "item"
+ += attr "rdf:about" (arr (mkPageURIStr baseURI . entityName) >>> mkText)
+ += ( eelem "title"
+ += (arr entityName >>> mkText)
+ )
+ += ( eelem "link"
+ += (arr (mkPageURIStr baseURI . entityName) >>> mkText)
+ )
+ += ( arrL (\ p -> case entitySummary p of
+ Nothing -> []
+ Just s -> [s])
+ >>>
+ eelem "description"
+ += mkText
+ )
+ += ( eelem "dc:date"
+ += ( arrIO (utcToLocalZonedTime . entityLastMod)
+ >>>
+ arr formatW3CDateTime
+ >>>
+ mkText
+ )
+ )
+ += ( eelem "trackback:ping"
+ += attr "rdf:resource" (arr (mkTrackbackURIStr baseURI . entityName) >>> mkText)
+ )
+ )
+ >>>
+ uniqueNamespacesFromDeclAndQNames
+ ) ) -<< page
+ where
+ mkPageURIStr :: URI -> PageName -> String
+ mkPageURIStr baseURI name
+ = uriToString id (mkPageURI baseURI name) ""
+
+ mkTrackbackURIStr :: URI -> PageName -> String
+ mkTrackbackURIStr baseURI name
+ = uriToString id (mkAuxiliaryURI baseURI ["trackback"] name) ""
+
+
readSubPage :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
Environment
-> a (PageName, Maybe XmlTree, PageName) XmlTree
)
)
) -< (dir, items)
- returnA -< outputXmlPage tree (pageListingToXHTML env)
+ returnA -< outputXmlPage' tree (pageListingToXHTML env) -- FIXME: rss 對應
pageListingToXHTML :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a XmlTree XmlTree
)
) -< name
returnA -< do setStatus NotFound
- outputXmlPage tree (notFoundToXHTML env)
+ outputXmlPage' tree (notFoundToXHTML env)
notFoundToXHTML :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a XmlTree XmlTree
( InterpTable
, makeMainXHTML
, makeSubXHTML
- , makeDraft
, makePreviewXHTML
+ , makePageLinkList
+ , makeDraft
)
where
addInlineCmdText doc (InlineCommand _ _ inlines) = mapM_ (addInlineText doc) inlines
+makePageLinkList :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
+ Storage
+ -> SystemConfig
+ -> InterpTable
+ -> a XmlTree [PageName]
+makePageLinkList sto sysConf interpTable
+ = proc tree
+ -> do wiki <- wikifyPage interpTable -< tree
+ pName <- getXPathTreesInDoc "/page/@name/text()" >>> getText -< tree
+ interpreted <- interpretCommands sto sysConf interpTable
+ -< (pName, Just tree, Just wiki, wiki)
+ returnA -< concatMap extractFromBlock interpreted
+ where
+ extractFromElem :: Element -> [PageName]
+ extractFromElem (Block b) = extractFromBlock b
+ extractFromElem (Inline i) = extractFromInline i
+
+ extractFromBlock :: BlockElement -> [PageName]
+ extractFromBlock (List _ items) = concatMap extractFromListItem items
+ extractFromBlock (DefinitionList defs) = concatMap extractFromDefinition defs
+ extractFromBlock (Preformatted inlines) = concatMap extractFromInline inlines
+ extractFromBlock (Paragraph inlines) = concatMap extractFromInline inlines
+ extractFromBlock (Div _ elems) = concatMap extractFromElem elems
+ extractFromBlock _ = []
+
+ extractFromInline :: InlineElement -> [PageName]
+ extractFromInline (Italic inlines) = concatMap extractFromInline inlines
+ extractFromInline (Bold inlines) = concatMap extractFromInline inlines
+ extractFromInline (Span _ inlines) = concatMap extractFromInline inlines
+ extractFromInline (PageLink (Just name) _ _) = [name]
+ extractFromInline _ = []
+
+ extractFromListItem :: ListItem -> [PageName]
+ extractFromListItem = concatMap extractFromElem
+
+ extractFromDefinition :: Definition -> [PageName]
+ extractFromDefinition (Definition term desc)
+ = concatMap extractFromInline term
+ ++
+ concatMap extractFromInline desc
+
+
wikifyParseError :: Arrow a => a ParseError WikiPage
wikifyParseError = proc err
-> returnA -< [Div [("class", "error")]