{-# LANGUAGE BlockArguments #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Main where import Data.Time.Calendar import Conduit import Control.Applicative import Control.Exception import Data.Binary.Builder import Data.Function import Data.List import Data.Maybe import Data.Ord import Data.Text qualified as T import Data.Time.Clock import Data.Time.Format.ISO8601 import Data.XML.Types import Network.HTTP.Conduit import Network.HTTP.Types import Network.Wai.Conduit import Network.Wai.Handler.Warp import Text.Atom.Conduit.Parse import Text.Atom.Conduit.Render import Text.Atom.Types import Text.Blaze import Text.Blaze.Html.Renderer.Utf8 import Text.Hamlet import Text.Printf import Text.XML.Stream.Parse import Text.XML.Stream.Render import Text.XML.Unresolved (elementToEvents) import UnliftIO.Concurrent (forkFinally) import UnliftIO.MVar env_FEED_TITLE :: T.Text env_FEED_TITLE = "code.nomath.org" env_FEED_ID :: T.Text env_FEED_ID = "code.nomath.org" env_FEED_URLS :: [String] env_FEED_URLS = [ "https://code.nomath.org/abuilder/atom", "https://code.nomath.org/anissue/atom", "https://code.nomath.org/apaperless/atom", "https://code.nomath.org/feed-nomath-org/atom", "https://code.nomath.org/infra/atom", "https://code.nomath.org/json2sql/atom", "https://code.nomath.org/nomath-org/atom", "https://code.nomath.org/static-nomath-org/atom" ] main :: IO () main = do runSettings ( defaultSettings & setPort 8080 & setBeforeMainLoop do printf "listening on 8080..\n" ) app app :: Application app req resp = do resp . responseStream status200 [] $ \write flush -> do feed <- runConduitRes do manager <- liftIO (newManager tlsManagerSettings) feeds <- mapM (lift . getFeed manager) env_FEED_URLS pure $ merge feeds write $ renderHtmlBuilder [shamlet|
#{feed}|] instance ToMarkup AtomFeed where toMarkup AtomFeed {..} = [shamlet|