diff --git a/Handler/Feed.hs b/Handler/Feed.hs index 76b0e6f..cf621b0 100644 --- a/Handler/Feed.hs +++ b/Handler/Feed.hs @@ -1,8 +1,6 @@ module Handler.Feed ( getFeedR - , getLtsFeedR - , getLtsMajorFeedR - , getNightlyFeedR + , getBranchFeedR ) where import Import @@ -13,21 +11,14 @@ import qualified Data.HashMap.Strict as HashMap import Text.Blaze (text) getFeedR :: Handler TypedContent -getFeedR = mkFeed "" . snd =<< getSnapshots 20 0 +getFeedR = mkFeed Nothing . snd =<< getSnapshots 20 0 -getLtsFeedR :: Handler TypedContent -getLtsFeedR = mkFeed "LTS" . snd =<< getLtsSnapshots 20 0 +getBranchFeedR :: StackageBranch -> Handler TypedContent +getBranchFeedR branch = mkFeed (Just branch) . snd =<< getBranchSnapshots branch 20 0 -getLtsMajorFeedR :: LtsMajor -> Handler TypedContent -getLtsMajorFeedR (LtsMajor v) = - mkFeed ("LTS-" <> tshow v) . snd =<< getLtsMajorSnapshots v 20 0 - -getNightlyFeedR :: Handler TypedContent -getNightlyFeedR = mkFeed "Nightly" . snd =<< getNightlySnapshots 20 0 - -mkFeed :: Text -> [Entity Snapshot] -> Handler TypedContent +mkFeed :: Maybe StackageBranch -> [Entity Snapshot] -> Handler TypedContent mkFeed _ [] = notFound -mkFeed branch snaps = do +mkFeed mBranch snaps = do entries <- forM snaps $ \(Entity snapid snap) -> do content <- getContent snapid snap return FeedEntry @@ -41,15 +32,20 @@ mkFeed branch snaps = do [] -> liftIO getCurrentTime x:_ -> return $ feedEntryUpdated x newsFeed Feed - { feedTitle = "Recent Stackage " <> branch <> " snapshots" + { feedTitle = title , feedLinkSelf = FeedR , feedLinkHome = HomeR , feedAuthor = "Stackage Project" - , feedDescription = text ("Recent Stackage " <> branch <> " snapshots") + , feedDescription = text title , feedLanguage = "en" , feedUpdated = updated , feedEntries = entries } + where + branchTitle NightlyBranch = "Nightly" + branchTitle LtsBranch = "LTS" + branchTitle (LtsMajorBranch x) = "LTS-" <> tshow x + title = "Recent Stackage " <> maybe "" branchTitle mBranch <> " snapshots" getContent :: SnapshotId -> Snapshot -> Handler Html getContent sid2 snap = do diff --git a/Stackage/Database.hs b/Stackage/Database.hs index ce1b92b..6c3d15d 100644 --- a/Stackage/Database.hs +++ b/Stackage/Database.hs @@ -37,6 +37,7 @@ module Stackage.Database , getLtsSnapshots , getLtsMajorSnapshots , getNightlySnapshots + , getBranchSnapshots , currentSchema , last5Lts5Nightly , snapshotsJSON @@ -71,6 +72,7 @@ import System.IO.Temp import qualified Database.Esqueleto as E import Data.Yaml (decode) import qualified Data.Aeson as A +import Types (StackageBranch(..)) currentSchema :: Int currentSchema = 1 @@ -675,6 +677,15 @@ getSnapshots l o = run $ (,) [] [LimitTo l, OffsetBy o, Desc SnapshotCreated] +getBranchSnapshots :: GetStackageDatabase m + => StackageBranch + -> Int -- ^ limit + -> Int -- ^ offset + -> m (Int, [Entity Snapshot]) +getBranchSnapshots NightlyBranch = getNightlySnapshots +getBranchSnapshots LtsBranch = getLtsSnapshots +getBranchSnapshots (LtsMajorBranch x) = getLtsMajorSnapshots x + getLtsSnapshots :: GetStackageDatabase m => Int -- ^ limit -> Int -- ^ offset diff --git a/config/routes b/config/routes index 8815f4f..ac7d596 100644 --- a/config/routes +++ b/config/routes @@ -47,9 +47,7 @@ /download/#SupportedArch/#Text DownloadGhcLinksR GET /feed FeedR GET -!/feed/#LtsMajor LtsMajorFeedR GET -/feed/lts LtsFeedR GET -/feed/nightly NightlyFeedR GET +/feed/#StackageBranch BranchFeedR GET /stack DownloadStackListR GET /stack/#Text DownloadStackR GET