Skip to content

Instantly share code, notes, and snippets.

@Tordek
Last active December 28, 2015 23:39
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 Tordek/7580693 to your computer and use it in GitHub Desktop.
Save Tordek/7580693 to your computer and use it in GitHub Desktop.
Playing around with Hakyll and Atom
postCtx :: Context String
postCtx =
dateFieldWith esArLocale "date" "%x" `mappend`
dateField "isoPublishDate" "%FT%TZ" `mappend`
defaultContext
authors :: [Person]
authors = [ Person
{ personName = "Tordek"
, personURI = Just absoluteRoot
, personEmail = Nothing
, personOther = []
}
]
hakyllGenerator = Generator
{ genURI = Just "http://jaspervdj.be/hakyll/tutorials.html"
, genVersion = Nothing
, genText = "Hakyll"
}
atomCompiler :: Context String -> [Item String] -> Item String -> Compiler (Item String)
atomCompiler itemContext items item = do
body <- atomCompiler' itemContext items item
return $ itemSetBody body item
atomCompiler' :: Context String -> [Item String] -> Item String -> Compiler String
atomCompiler' itemContext items item = do
lastUpdateDate <- lastUpdateDateCompiler
recentPosts <- atomEntryCompiler itemContext items
return . showTopElement . xmlFeed $ Feed
{ feedId = absoluteRoot
, feedTitle = TextString "Feed for Tordek"
, feedUpdated = lastUpdateDate
, feedAuthors = authors
, feedCategories = [] -- all blog cats?
, feedContributors = []
, feedGenerator = Just hakyllGenerator
, feedIcon = Just "http://tordek.com.ar/tordek.png"
, feedLinks = [] -- missing self link
, feedLogo = Just "http://tordek.com.ar/tordek.png"
, feedRights = Nothing
, feedSubtitle = Nothing
, feedEntries = recentPosts
, feedAttrs = []
, feedOther = []
}
where
lastUpdateDateCompiler = case items of
[] -> return "Unknown"
(x:_) -> unContext itemContext "isoPublishDate" x >>= getString "isoPublishDate"
atomEntryCompiler :: Context String -> [Item String] -> Compiler [Entry]
atomEntryCompiler itemContext = mapM (atomSingleEntryCompiler itemContext)
atomSingleEntryCompiler :: Context String -> Item String -> Compiler Entry
atomSingleEntryCompiler itemContext item@(Item id body) = do
url <- getField "url"
title <- getField "title"
update <- getField "isoPublishDate"
return $ (nullEntry (absoluteRoot ++ url)
(TextString title)
update) { entryContent = Just (HTMLContent body) }
-- return $ Entry
-- { entryId = url
-- , entryTitle = title
-- ,
-- }
where
getField s = unContext itemContext s item >>= getString s
getString _ (StringField s) = return s
getString x _ = fail $
"atomSingleEntryCompiler: expected StringField " ++
x ++ " but got something different."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment