diff options
author | Joey Hess <joey@kitenet.net> | 2014-04-07 16:55:04 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-04-07 16:55:04 -0400 |
commit | b59b2d9686e3ad5b6f361505182cede819847bff (patch) | |
tree | 6fb3d8366bc113a5f05098b2998fde53c4f76186 /Command/ImportFeed.hs | |
parent | d865c8b9f59f7619d0fbff873cbb43d559ca975e (diff) |
importfeed: Filename template can now contain an itempubdate variable. Needs feed 0.3.9.2.
Diffstat (limited to 'Command/ImportFeed.hs')
-rw-r--r-- | Command/ImportFeed.hs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Command/ImportFeed.hs b/Command/ImportFeed.hs index 50f4278b6..3f629af6e 100644 --- a/Command/ImportFeed.hs +++ b/Command/ImportFeed.hs @@ -15,6 +15,8 @@ import Text.Feed.Types import qualified Data.Set as S import qualified Data.Map as M import Data.Time.Clock +import Data.Time.Format +import System.Locale import Common.Annex import qualified Annex @@ -212,6 +214,7 @@ feedFile tmpl i extension = Utility.Format.format tmpl $ M.fromList , fieldMaybe "itemdescription" $ getItemDescription $ item i , fieldMaybe "itemrights" $ getItemRights $ item i , fieldMaybe "itemid" $ snd <$> getItemId (item i) + , fieldMaybe "itempubdate" $ pubdate $ item i , ("extension", sanitizeFilePath extension) ] where @@ -221,6 +224,12 @@ feedFile tmpl i extension = Utility.Format.format tmpl $ M.fromList fieldMaybe k Nothing = (k, "none") fieldMaybe k (Just v) = field k v + pubdate itm = case getItemPublishDate itm :: Maybe (Maybe UTCTime) of + Just (Just d) -> Just $ + formatTime defaultTimeLocale "%F" d + -- if date cannot be parsed, use the raw string + _ -> replace "/" "-" <$> getItemPublishDateString itm + {- Called when there is a problem with a feed. - Throws an error if the feed is broken, otherwise shows a warning. -} feedProblem :: URLString -> String -> Annex () |