aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2016-09-01 15:51:10 +0200
committerFélix Sipma <felix.sipma@no-log.org>2016-09-01 15:51:10 +0200
commit50e5224dc2ccec65a03308c399f1c23b026a8886 (patch)
tree6396383082725159f56564ce2fda6e1f302172ec
parent3420efcfbf1c1555669ecdc41b78641a97197049 (diff)
Atom: allow parsing "published" instead of "updated" for entries
-rw-r--r--src/Atom.hs26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/Atom.hs b/src/Atom.hs
index 9514576..1aea270 100644
--- a/src/Atom.hs
+++ b/src/Atom.hs
@@ -22,17 +22,25 @@ import Parse
localNameFilter :: T.Text -> Axis
localNameFilter ln = checkName (\name -> nameLocalName name == ln)
+parseFieldContent :: T.Text -> Cursor -> [T.Text]
+parseFieldContent field c = c $/ localNameFilter field &// content
+
-- | "id" is a required element
parseId :: Cursor -> T.Text
-parseId c = mconcat $ c $/ localNameFilter "id" &// content
+parseId = mconcat . parseFieldContent "id"
-- | "title" is a required element
parseTitle :: Cursor -> T.Text
-parseTitle c = mconcat $ c $/ localNameFilter "title" &// content
+parseTitle = mconcat . parseFieldContent "title"
-- | "updated" is a required element
parseUpdated :: MonadLogger m => Cursor -> m (Maybe UTCTime)
-parseUpdated c = parseW3Rfc822 $ mconcat $ c $/ localNameFilter "updated" &// content
+parseUpdated c = parseW3Rfc822 $ mconcat $ parseFieldContent "updated" c
+
+parseEntryUpdated :: MonadLogger m => Cursor -> m (Maybe UTCTime)
+parseEntryUpdated c = case parseFieldContent "updated" c of
+ [] -> parseW3Rfc822 $ mconcat $ parseFieldContent "published" c
+ us -> parseW3Rfc822 $ mconcat us
parseLink :: Cursor -> Link
parseLink c = do
@@ -46,11 +54,11 @@ parseLinks :: Cursor -> [Link]
parseLinks c = c $/ localNameFilter "link" &| parseLink
parsePerson :: Cursor -> Person
-parsePerson c = do
- let name = mconcat $ c $/ localNameFilter "name" &// content
- uri = Nothing -- TODO
- email = Nothing -- TODO
- Person name uri email
+parsePerson c = Person name uri email
+ where
+ name = mconcat $ parseFieldContent "name" c
+ uri = Nothing -- TODO
+ email = Nothing -- TODO
parseAuthors :: Cursor -> [Person]
parseAuthors c = c $/ localNameFilter "author" &| parsePerson
@@ -82,7 +90,7 @@ parseEntry c = do
content' = parseContent c
links = parseLinks c
when (isNothing content') ($logWarn $ formatContentEmptyError id' title)
- mupdated <- parseUpdated c
+ mupdated <- parseEntryUpdated c
maybe (parseUpdatedFailed id' title) (\updated -> return $ Just $ Entry id' title updated authors content' links) mupdated
where
parseUpdatedFailed i t = do