1 module Rakka.Wiki.Interpreter.Trackback
8 import Network.HTTP.Lucu.RFC1123DateTime
11 import Rakka.SystemConfig
12 import Rakka.TrackBack
14 import Rakka.Wiki.Interpreter
17 interpreters :: [Interpreter]
18 interpreters = [ trackbackURLInterp
23 trackbackURLInterp :: Interpreter
25 = InlineCommandInterpreter {
26 iciName = "trackbackURL"
28 = \ ctx _ -> case ctxPageName ctx of
30 -> return (Text "No trackbacks for this page.")
32 -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
33 let uri = mkAuxiliaryURI baseURI ["trackback"] name
34 return $ ExternalLink uri (Just "Trackback URL")
38 trackbacksInterp :: Interpreter
40 = BlockCommandInterpreter {
41 bciName = "trackbacks"
44 do trackbacks <- case ctxPageName ctx of
48 -> liftM (fromMaybe [])
49 (getAttachment (ctxStorage ctx) name "trackbacks" Nothing)
50 items <- mapM mkListItem trackbacks
52 let divElem = Div [("class", "trackbacks")] [list]
53 list = Block (List Bullet items)
58 mkListItem :: TrackBack -> IO ListItem
60 = do zonedTime <- utcToLocalZonedTime (tbTime tb)
62 let anchor = Just (Inline (ExternalLink (tbURL tb) label))
63 label = case (tbTitle tb, tbBlogName tb) of
64 (Nothing , Nothing ) -> Nothing
65 (Just title, Nothing ) -> Just title
66 (Nothing , Just blogName) -> Just blogName
67 (Just title, Just blogName) -> Just (title ++ " (" ++ blogName ++ ")")
68 date = Just ( Block ( Div [("class", "date")]
69 [Inline (Text (formatRFC1123DateTime zonedTime))]
72 excerpt = do e <- tbExcerpt tb
73 return $ Block $ Paragraph [Text e]
75 return $ catMaybes [anchor, date, excerpt]