From 20d08ffa316dc020f7b5c5ba2e5b07783afced83 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 11 Oct 2015 14:16:10 +0300 Subject: [PATCH] /feed --- Application.hs | 1 + Foundation.hs | 2 ++ Handler/Feed.hs | 28 ++++++++++++++++++++++++++++ config/routes | 1 + stackage-server.cabal | 2 ++ 5 files changed, 34 insertions(+) create mode 100644 Handler/Feed.hs diff --git a/Application.hs b/Application.hs index 76bc37b..1bf3ab4 100644 --- a/Application.hs +++ b/Application.hs @@ -45,6 +45,7 @@ import Handler.Sitemap import Handler.BuildPlan import Handler.Download import Handler.OldLinks +import Handler.Feed -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/Foundation.hs b/Foundation.hs index 6a2dc4a..d4e59b3 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -12,6 +12,7 @@ import Text.Hamlet (hamletFile) import Types import Yesod.Core.Types (Logger) import Yesod.Default.Config +import Yesod.AtomFeed import Yesod.GitRepo import Stackage.Database @@ -70,6 +71,7 @@ defaultLayoutWithContainer insideContainer widget = do [ js_jquery_js , js_bootstrap_js ])) + atomLink FeedR "Recent Stackage snapshots" $(widgetFile "default-layout") mcurr <- getCurrentRoute diff --git a/Handler/Feed.hs b/Handler/Feed.hs new file mode 100644 index 0000000..cb2ab96 --- /dev/null +++ b/Handler/Feed.hs @@ -0,0 +1,28 @@ +module Handler.Feed where + +import Import +import Stackage.Database + +getFeedR :: Handler TypedContent +getFeedR = do + (_, snaps) <- getSnapshots 20 0 + let entries = flip map snaps $ \snap -> FeedEntry + { feedEntryLink = SnapshotR (snapshotName snap) StackageHomeR + , feedEntryUpdated = UTCTime (snapshotCreated snap) 0 + , feedEntryTitle = prettyName (snapshotName snap) (snapshotGhc snap) + , feedEntryContent = "" + } + updated <- + case entries of + [] -> liftIO getCurrentTime + x:_ -> return $ feedEntryUpdated x + newsFeed Feed + { feedTitle = "Recent Stackage snapshots" + , feedLinkSelf = FeedR + , feedLinkHome = HomeR + , feedAuthor = "Stackage Project" + , feedDescription = "Recent Stackage snapshots" + , feedLanguage = "en" + , feedUpdated = updated + , feedEntries = entries + } diff --git a/config/routes b/config/routes index e2eedcd..9baae5e 100644 --- a/config/routes +++ b/config/routes @@ -45,3 +45,4 @@ /download/snapshots.json DownloadSnapshotsJsonR GET /download/lts-snapshots.json DownloadLtsSnapshotsJsonR GET /download/#SupportedArch/#Text DownloadGhcLinksR GET +/feed FeedR GET diff --git a/stackage-server.cabal b/stackage-server.cabal index ead55a7..6b80d75 100644 --- a/stackage-server.cabal +++ b/stackage-server.cabal @@ -48,6 +48,7 @@ library Handler.BuildPlan Handler.Download Handler.OldLinks + Handler.Feed if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT @@ -136,6 +137,7 @@ library , yesod-auth >= 1.4 && < 1.5 , yesod-core >= 1.4 && < 1.5 , yesod-form >= 1.4 && < 1.5 + , yesod-newsfeed , yesod-static >= 1.5 && < 1.6 , zlib >= 0.5 && < 0.6 , unordered-containers >= 0.2 && < 0.3