diff --git a/app/Main.hs b/app/Main.hs index 8944836..9699dd1 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -12,6 +12,7 @@ data Args = Args , directory :: FilePath , fileHead :: FilePath , verbose :: Bool + , refs :: Bool , cgi :: Bool } @@ -36,6 +37,9 @@ args = Args ( long "verbose" <> short 'v' <> help "Verbose mode") + <*> switch + ( long "references" + <> help "Generate link reference based on first line of document" ) <*> switch ( long "cgi" <> help "Output gemini file header") @@ -49,16 +53,24 @@ main = parseArgs =<< execParser opts <> header "Generate a gemini page index") parseArgs :: Args -> IO() -parseArgs (Args t d h False False) = do - putStrLn $ "# " ++ t - putStrLn h - mkIndex =<< getDirectoryContents d -parseArgs (Args t d h False True) = do - putStr success - putStrLn $ "# " ++ t - putStrLn h - mkIndex =<< getDirectoryContents d -parseArgs _ = putStrLn "fiets" +parseArgs (Args t dir h v c r) = do + if c then do + putStr success + putStrLn $ "# " ++ t + else putStrLn $ "# " ++ t + if not (null h) + then putStr $ "\n\n" ++ h ++ "\n\n" + else putStr "\n" + mkIndex r . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir -mkIndex :: [String] -> IO () -mkIndex = mapM_ (putStrLn . ("=> " ++)) . filter (isSuffixOf ".gmi") +mkIndex :: Bool -> [String] -> IO () +mkIndex True l = mapM_ (putStrLn . ("=> " ++)) l + -- where firstLine f = do + -- print $ head . lines =<< readFile f +mkIndex False l = mapM_ (putStrLn . ("=> " ++)) l + +firstLine :: FilePath -> IO () +firstLine f = do + putStr . head . lines =<< readFile f + +--compose = (++) <$> ("=> " ++) <*> (show . length) <*> (head . lines =<< readFile)