diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Main.hs | 110 |
1 files changed, 86 insertions, 24 deletions
diff --git a/app/Main.hs b/app/Main.hs index 6462846..4e9b373 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,4 +1,5 @@ {-# LANGUAGE BlockArguments #-} +{-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedStrings #-} @@ -8,6 +9,7 @@ module Main where +import Conduit import Control.Arrow hiding (app) import Control.Concurrent import Control.Exception @@ -30,11 +32,14 @@ import Network.Wai.Handler.Warp import System.Environment import System.FilePath import System.IO.Unsafe +import Text.Atom.Conduit.Render +import Text.Atom.Types import Text.Blaze import Text.Blaze.Html.Renderer.Utf8 import Text.Cassius import Text.Hamlet import Text.Printf +import Text.XML.Stream.Render env_REPOSITORIES :: [String] env_REPOSITORIES = @@ -57,30 +62,87 @@ main = do app app :: Application -app _ resp = do - resp . responseStream status200 [] $ \write _ -> do - commits <- - reverse . sortOn (.createdAt) - <$> getCommitsConcurrently env_REPOSITORIES - let commitsPerDay = - (map (\xs -> (utctDay . (.createdAt) $ head xs, xs))) $ - groupBy ((==) `on` (utctDay . (.createdAt))) commits - write $ - renderHtmlBuilder - [shamlet| - <html lang=en> - <head> - <meta charset=utf-8> - <title>feed.nomath.org</title> - <link rel=icon href=https://static.nomath.org/favicon.ico> - <meta name=viewport content="width=device-width, initial-scale=1"> - <link rel=stylesheet type=text/css href=https://static.nomath.org/base.css> - <style type=text/css> - #{renderCss css} - <body> - <h1>feed.nomath.org - #{commitsPerDay} - |] +app req resp = do + if + | rawPathInfo req == "/feed" -> + resp + . responseStream + status200 + [ ("content-type", "application/atom+xml") + ] + $ \write _ -> do + commits <- + reverse . sortOn (.createdAt) + <$> getCommitsConcurrently env_REPOSITORIES + feedUpdated <- getCurrentTime + runConduit $ + renderAtomFeed + AtomFeed + { feedAuthors = [], + feedCategories = [], + feedContributors = [], + feedEntries = + map + ( \commit -> + AtomEntry + { entryAuthors = [], + entryCategories = [], + entryContent = AtomContentInlineText TypeText <$> (snd commit.message), + entryContributors = [], + entryId = "feed.nomath.org/" <> commit.repository <> "/" <> commit.hash, + entryLinks = [], + entryPublished = Nothing, + entryRights = Nothing, + entrySource = Nothing, + entrySummary = Nothing, + entryTitle = AtomPlainText TypeText (fst commit.message), + entryUpdated = commit.createdAt + } + ) + commits, + feedGenerator = Nothing, + feedIcon = Nothing, + feedId = "https://feed.nomath.org", + feedLinks = [], + feedLogo = Nothing, + feedRights = Nothing, + feedSubtitle = Nothing, + feedTitle = AtomPlainText TypeText "feed.nomath.org", + feedUpdated = feedUpdated + } + .| renderBuilder def + .| mapM_C write + | rawPathInfo req == "/" -> + resp + . responseStream + status200 + [ ("content-type", "text/html") + ] + $ \write _ -> do + commits <- + reverse . sortOn (.createdAt) + <$> getCommitsConcurrently env_REPOSITORIES + let commitsPerDay = + (map (\xs -> (utctDay . (.createdAt) $ head xs, xs))) $ + groupBy ((==) `on` (utctDay . (.createdAt))) commits + write $ + renderHtmlBuilder + [shamlet| + <html lang=en> + <head> + <meta charset=utf-8> + <link rel=alternate type=application/atom+xml href=/feed> + <title>feed.nomath.org</title> + <link rel=icon href=https://static.nomath.org/favicon.ico> + <meta name=viewport content="width=device-width, initial-scale=1"> + <link rel=stylesheet type=text/css href=https://static.nomath.org/base.css> + <style type=text/css> + #{renderCss css} + <body> + <h1>feed.nomath.org + #{commitsPerDay} + |] + | otherwise -> resp (responseLBS status404 [] "Not found") css :: Css css = |