From 16472c49d5b8e56520957abb452b6be12c94b04f Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 19 Dec 2014 21:59:55 +0100 Subject: [PATCH] toying around with the feeds --- Handler/RootFeed.hs | 23 +++++++++++------------ Helper.hs | 11 +++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Handler/RootFeed.hs b/Handler/RootFeed.hs index 7f74061..0756dc7 100644 --- a/Handler/RootFeed.hs +++ b/Handler/RootFeed.hs @@ -2,8 +2,7 @@ module Handler.RootFeed where import Import import Yesod -import Helper -import qualified Data.ByteString.Lazy as LB +import Yesod.Static import qualified Data.Text as T import Data.Maybe import Data.Time @@ -46,9 +45,6 @@ instance RepFeed RepAtom where return $ Left $ map (\ent -> (entityKey ent, url $ MediumR $ commentOrigin $ entityVal ent)) commEnts Right mediaEnts -> return $ Right $ map (\ent -> (entityKey ent, url $ MediumR $ entityKey ent)) mediaEnts --- media <- case items of --- [Entity _ (Medium _ _ _ _ _ _ _ _ _)] -> return $ True --- [Entity _ (Comment _ _ _ _ _ _)] -> return $ False return $ RepAtom $ toContent $ [xhamlet|$newline always #{iso8601 $ utcToZonedTime tz $ mediumTime medium} #{mediumDescription medium} $of Left comments $forall (Entity commentId comment) <- comments @@ -93,7 +89,7 @@ instance RepFeed RepAtom where #{fromJust $ lookup commentId $ fromLeft [] links} #{iso8601 $ utcToZonedTime tz $ commentTime comment} #{commentContent comment} - |] url + |] url newtype RepRss = RepRss Content deriving (ToContent) @@ -134,8 +130,8 @@ instance RepFeed RepRss where #{rfc822 $ mediumTime medium} #{fromJust $ lookup mediumId $ fromRight [] links} - + $of Left comments $forall (Entity commentId comment) <- comments @@ -170,11 +166,13 @@ getAlbumFeedRssR = getAlbumFeedR getAlbumFeedR :: RepFeed a => AlbumId -> Handler a getAlbumFeedR albumId = do album <- runDB $ get404 albumId + url <- getUrlRender recentMedia <- runDB $ selectList [MediumAlbum ==. albumId] [Desc MediumTime, LimitTo 10] renderFeed Parameters { pTitle = "Eidolon :: Latest media in album " `T.append` (albumTitle album) , pLink = AlbumR albumId - , pImage = T.pack $ fromMaybe "" (albumSamplePic album) + , pImage = url $ StaticR $ StaticRoute + (drop 2 $ T.splitOn "/" $ T.pack $ fromMaybe "/static/img/album.jpg" $ albumSamplePic album) [] } (Right recentMedia) getCommentFeedAtomR :: MediumId -> Handler RepAtom @@ -186,9 +184,10 @@ getCommentFeedRssR = getCommentFeedR getCommentFeedR :: RepFeed a => MediumId -> Handler a getCommentFeedR mediumId = do medium <- runDB $ get404 mediumId + url <- getUrlRender recentComments <- runDB $ selectList [CommentOrigin ==. mediumId] [Desc CommentTime, LimitTo 10] renderFeed Parameters { pTitle = "Eidolon :: Newest comments on " `T.append` (mediumTitle medium) , pLink = MediumR mediumId - , pImage = T.pack $ mediumThumb medium + , pImage = url $ StaticR $ mediumStaticThumbRoute medium } (Left recentComments) diff --git a/Helper.hs b/Helper.hs index 1acfeed..e4e24ac 100644 --- a/Helper.hs +++ b/Helper.hs @@ -16,10 +16,13 @@ module Helper , iso8601 , localTimeToZonedTime , rfc822 + , mediumStaticImageRoute + , mediumStaticThumbRoute ) where import Prelude +import Yesod.Static import Model import Control.Applicative import Control.Monad.Trans.Class @@ -174,3 +177,11 @@ localTimeToZonedTime tz = --rfc822 :: LocalTime -> String rfc822 = formatTime defaultTimeLocale rfc822DateFormat + +mediumStaticImageRoute :: Medium -> Route Static +mediumStaticImageRoute medium = + StaticRoute (drop 2 $ T.splitOn "/" $ T.pack $ mediumPath medium) [] + +mediumStaticThumbRoute :: Medium -> Route Static +mediumStaticThumbRoute medium = + StaticRoute (drop 2 $ T.splitOn "/" $ T.pack $ mediumThumb medium) []