aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2016-09-01 16:40:56 +0200
committerFélix Sipma <felix.sipma@no-log.org>2016-09-01 16:40:56 +0200
commit9057c81a2057106b9b3a05225ce5ca07e89a203e (patch)
tree206ff3d6d41bb8b51f0194abe1aec5a83fb59405
parent8217b9d703663d86a96d3ca04e6a604b3254a725 (diff)
RSS1: minor refactoring
-rw-r--r--src/RSS1.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/RSS1.hs b/src/RSS1.hs
index cd5ad78..27e0254 100644
--- a/src/RSS1.hs
+++ b/src/RSS1.hs
@@ -20,16 +20,19 @@ 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
+
parseId :: Cursor -> T.Text
-parseId c = mconcat $ c $/ localNameFilter "guid" &// content
+parseId = mconcat . parseFieldContent "guid"
parseTitle :: Cursor -> T.Text
parseTitle c =
- mconcat (c $/ localNameFilter "title" &// content)
+ mconcat (parseFieldContent "title" c)
`mappend` mconcat (c $/ element "{http://purl.org/dc/elements/1.1/}subject" &// content)
parseUpdated :: MonadLogger m => [Entry] -> Cursor -> m (Maybe UTCTime)
-parseUpdated e c = case mconcat $ c $/ localNameFilter "lastBuildDate" &// content of
+parseUpdated e c = case mconcat $ parseFieldContent "lastBuildDate" c of
"" -> case e of
[] -> return (Just $ read "1970-01-01 00:00:00 UTC")
_ -> case map entryUpdated e of
@@ -39,7 +42,7 @@ parseUpdated e c = case mconcat $ c $/ localNameFilter "lastBuildDate" &// conte
parseEntryUpdated :: MonadLogger m => Cursor -> m (Maybe UTCTime)
parseEntryUpdated c = parseW3Rfc822 $
- mconcat (c $/ localNameFilter "pubDate" &// content)
+ mconcat (parseFieldContent "pubDate" c)
`mappend` mconcat (c $/ element "{http://purl.org/dc/elements/1.1/}date" &// content)
parseLink :: Cursor -> Link