Created
March 28, 2019 19:06
-
-
Save Taneb/fc9cc3b5d859c4e29422a6597dc04d57 to your computer and use it in GitHub Desktop.
Generate RSS feed from list of Git references and timestamps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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