Skip to content

Instantly share code, notes, and snippets.

@Taneb
Created March 28, 2019 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Taneb/fc9cc3b5d859c4e29422a6597dc04d57 to your computer and use it in GitHub Desktop.
Save Taneb/fc9cc3b5d859c4e29422a6597dc04d57 to your computer and use it in GitHub Desktop.
Generate RSS feed from list of Git references and timestamps
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
module Main where
import Data.Maybe
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Network.URI
import Text.RSS
data Record = Record
{ ref :: String
, time :: UTCTime
}
parseRecord :: String -> Maybe Record
parseRecord s = case words s of
[ref, posixSecondsToUTCTime . realToFrac . read -> time] -> Just Record {..}
_ -> Nothing
recordItem :: Record -> Item
recordItem Record{..} =
[ Title $ "nixos-19.03-small " ++ ref
, Link $ fromJust $ parseURI "https://releases.nixos.org/nixos/19.03-small"
, Description ref
, PubDate time
]
main :: IO ()
main = interact $
showXML .
rssToXML .
RSS "nixos-19.03-small" (fromJust $ parseURI "https://channels.nix.gsc.io/nixos-19.03-small") "nixos-19.03-small" [TTL 15] .
map recordItem .
mapMaybe parseRecord .
lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment