Anonymous avatar Anonymous committed 40a015a

Improved the OPML import function.

Comments (0)

Files changed (1)

 -- }}}
 
 
--- | Return the Haskell code to write in the configuration file to add a feed.
+-- | Return the Haskell code to write in the configuration file to add feeds.
 addFeeds :: (MonadBase IO m) => [(String, [String])] -> m ()
-addFeeds feeds = forM_ feeds addFeedsGroup
+addFeeds feeds = do
+    io . putStrLn . unlines $
+        "import Imm":
+        "import Control.Lens":
+        "import System.FilePath":
+        "":
+        "main :: IO ()":
+        "main = imm myFeeds":
+        "":
+        "maildirRoot = \"/home/<user>/feeds\"   -- TODO: fill <user>":
+        "":
+        ("myFeeds = concat [" ++ intercalate ", " (map (map toLower . concat . words . fst) feeds) ++ "]"):
+        []
+
+    forM_ feeds addFeedsGroup
 
 addFeedsGroup :: (MonadBase IO m) => (String, [String]) -> m ()
 addFeedsGroup (groupTitle, uris) = io $ do
     -- guard (not $ null uris)
-    putStrLn . unlines $ [
-        "-- Group " ++ groupTitle,
-        map toLower (concat . words $ groupTitle) ++ " = [",
-        ("    " ++) . intercalate ",\n    " $ map show uris,
-       "]"]
+    putStr . unlines $
+        ("-- Group " ++ groupTitle):
+        (groupID ++ "Config = set maildir (maildirRoot </> \"" ++ groupID ++ "\")"):
+        (groupID ++ "       = zip (repeat " ++ groupID ++ "Config) $"):
+        []
+    putStr . unlines $ map (\u -> "    " ++ show u ++ ":") uris
+    putStrLn "    []"
+    putStrLn ""
+  where
+    groupID = map toLower . concat . words $ groupTitle
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.