mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-26 19:01:56 +01:00
Use StackageBranch for Feed
This commit is contained in:
parent
be32c1a177
commit
62c0789ca6
@ -1,8 +1,6 @@
|
|||||||
module Handler.Feed
|
module Handler.Feed
|
||||||
( getFeedR
|
( getFeedR
|
||||||
, getLtsFeedR
|
, getBranchFeedR
|
||||||
, getLtsMajorFeedR
|
|
||||||
, getNightlyFeedR
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
@ -13,21 +11,14 @@ import qualified Data.HashMap.Strict as HashMap
|
|||||||
import Text.Blaze (text)
|
import Text.Blaze (text)
|
||||||
|
|
||||||
getFeedR :: Handler TypedContent
|
getFeedR :: Handler TypedContent
|
||||||
getFeedR = mkFeed "" . snd =<< getSnapshots 20 0
|
getFeedR = mkFeed Nothing . snd =<< getSnapshots 20 0
|
||||||
|
|
||||||
getLtsFeedR :: Handler TypedContent
|
getBranchFeedR :: StackageBranch -> Handler TypedContent
|
||||||
getLtsFeedR = mkFeed "LTS" . snd =<< getLtsSnapshots 20 0
|
getBranchFeedR branch = mkFeed (Just branch) . snd =<< getBranchSnapshots branch 20 0
|
||||||
|
|
||||||
getLtsMajorFeedR :: LtsMajor -> Handler TypedContent
|
mkFeed :: Maybe StackageBranch -> [Entity Snapshot] -> 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 _ [] = notFound
|
mkFeed _ [] = notFound
|
||||||
mkFeed branch snaps = do
|
mkFeed mBranch snaps = do
|
||||||
entries <- forM snaps $ \(Entity snapid snap) -> do
|
entries <- forM snaps $ \(Entity snapid snap) -> do
|
||||||
content <- getContent snapid snap
|
content <- getContent snapid snap
|
||||||
return FeedEntry
|
return FeedEntry
|
||||||
@ -41,15 +32,20 @@ mkFeed branch snaps = do
|
|||||||
[] -> liftIO getCurrentTime
|
[] -> liftIO getCurrentTime
|
||||||
x:_ -> return $ feedEntryUpdated x
|
x:_ -> return $ feedEntryUpdated x
|
||||||
newsFeed Feed
|
newsFeed Feed
|
||||||
{ feedTitle = "Recent Stackage " <> branch <> " snapshots"
|
{ feedTitle = title
|
||||||
, feedLinkSelf = FeedR
|
, feedLinkSelf = FeedR
|
||||||
, feedLinkHome = HomeR
|
, feedLinkHome = HomeR
|
||||||
, feedAuthor = "Stackage Project"
|
, feedAuthor = "Stackage Project"
|
||||||
, feedDescription = text ("Recent Stackage " <> branch <> " snapshots")
|
, feedDescription = text title
|
||||||
, feedLanguage = "en"
|
, feedLanguage = "en"
|
||||||
, feedUpdated = updated
|
, feedUpdated = updated
|
||||||
, feedEntries = entries
|
, 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 :: SnapshotId -> Snapshot -> Handler Html
|
||||||
getContent sid2 snap = do
|
getContent sid2 snap = do
|
||||||
|
|||||||
@ -37,6 +37,7 @@ module Stackage.Database
|
|||||||
, getLtsSnapshots
|
, getLtsSnapshots
|
||||||
, getLtsMajorSnapshots
|
, getLtsMajorSnapshots
|
||||||
, getNightlySnapshots
|
, getNightlySnapshots
|
||||||
|
, getBranchSnapshots
|
||||||
, currentSchema
|
, currentSchema
|
||||||
, last5Lts5Nightly
|
, last5Lts5Nightly
|
||||||
, snapshotsJSON
|
, snapshotsJSON
|
||||||
@ -71,6 +72,7 @@ import System.IO.Temp
|
|||||||
import qualified Database.Esqueleto as E
|
import qualified Database.Esqueleto as E
|
||||||
import Data.Yaml (decode)
|
import Data.Yaml (decode)
|
||||||
import qualified Data.Aeson as A
|
import qualified Data.Aeson as A
|
||||||
|
import Types (StackageBranch(..))
|
||||||
|
|
||||||
currentSchema :: Int
|
currentSchema :: Int
|
||||||
currentSchema = 1
|
currentSchema = 1
|
||||||
@ -675,6 +677,15 @@ getSnapshots l o = run $ (,)
|
|||||||
[]
|
[]
|
||||||
[LimitTo l, OffsetBy o, Desc SnapshotCreated]
|
[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
|
getLtsSnapshots :: GetStackageDatabase m
|
||||||
=> Int -- ^ limit
|
=> Int -- ^ limit
|
||||||
-> Int -- ^ offset
|
-> Int -- ^ offset
|
||||||
|
|||||||
@ -47,9 +47,7 @@
|
|||||||
/download/#SupportedArch/#Text DownloadGhcLinksR GET
|
/download/#SupportedArch/#Text DownloadGhcLinksR GET
|
||||||
|
|
||||||
/feed FeedR GET
|
/feed FeedR GET
|
||||||
!/feed/#LtsMajor LtsMajorFeedR GET
|
/feed/#StackageBranch BranchFeedR GET
|
||||||
/feed/lts LtsFeedR GET
|
|
||||||
/feed/nightly NightlyFeedR GET
|
|
||||||
|
|
||||||
/stack DownloadStackListR GET
|
/stack DownloadStackListR GET
|
||||||
/stack/#Text DownloadStackR GET
|
/stack/#Text DownloadStackR GET
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user