Link names

This commit is contained in:
Nox Sluijtman 2023-07-31 14:32:56 +02:00
parent 0001730497
commit 5d241e19f8

View file

@ -12,6 +12,7 @@ data Args = Args
, directory :: FilePath , directory :: FilePath
, fileHead :: FilePath , fileHead :: FilePath
, verbose :: Bool , verbose :: Bool
, refs :: Bool
, cgi :: Bool , cgi :: Bool
} }
@ -36,6 +37,9 @@ args = Args
( long "verbose" ( long "verbose"
<> short 'v' <> short 'v'
<> help "Verbose mode") <> help "Verbose mode")
<*> switch
( long "references"
<> help "Generate link reference based on first line of document" )
<*> switch <*> switch
( long "cgi" ( long "cgi"
<> help "Output gemini file header") <> help "Output gemini file header")
@ -49,16 +53,24 @@ main = parseArgs =<< execParser opts
<> header "Generate a gemini page index") <> header "Generate a gemini page index")
parseArgs :: Args -> IO() parseArgs :: Args -> IO()
parseArgs (Args t d h False False) = do parseArgs (Args t dir h v c r) = do
putStrLn $ "# " ++ t if c then do
putStrLn h
mkIndex =<< getDirectoryContents d
parseArgs (Args t d h False True) = do
putStr success putStr success
putStrLn $ "# " ++ t putStrLn $ "# " ++ t
putStrLn h else putStrLn $ "# " ++ t
mkIndex =<< getDirectoryContents d if not (null h)
parseArgs _ = putStrLn "fiets" then putStr $ "\n\n" ++ h ++ "\n\n"
else putStr "\n"
mkIndex r . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
mkIndex :: [String] -> IO () mkIndex :: Bool -> [String] -> IO ()
mkIndex = mapM_ (putStrLn . ("=> " ++)) . filter (isSuffixOf ".gmi") 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)