summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-02 13:37:06 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-02 13:37:06 +0100
commit18b1d5ebb9a903bc40325ac82c7df2b643301908 (patch)
tree2d1243f09d3c3a786a07bff636e177f3e52a76dc
parentea152cdf66aaab165178c4fcfa575fc4b898bc44 (diff)
add atom feed
-rw-r--r--app/Main.hs110
-rw-r--r--feed-nomath-org.cabal3
2 files changed, 89 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 =
diff --git a/feed-nomath-org.cabal b/feed-nomath-org.cabal
index a84b10c..9438be2 100644
--- a/feed-nomath-org.cabal
+++ b/feed-nomath-org.cabal
@@ -15,9 +15,11 @@ executable feed-nomath-org
default-language: GHC2021
ghc-options: -Wall -threaded
build-depends:
+ atom-conduit,
base,
blaze-html,
blaze-markup,
+ conduit,
filepath,
gitlib,
gitlib-libgit2,
@@ -29,3 +31,4 @@ executable feed-nomath-org
time,
wai-conduit,
warp,
+ xml-conduit,