Gemini file header

This commit is contained in:
Nox Sluijtman 2023-07-31 00:29:26 +02:00
parent 61746521df
commit 0dafb22a60

View file

@ -1,10 +1,12 @@
module Main where module Main where
import System.Directory import System.Directory
import System.Environment
import Options.Applicative import Options.Applicative
import Data.List import Data.List
success :: String
success = "20 text/gemini; lang=en; charset=utf-8\r\n"
data Args = Args data Args = Args
{ title :: String { title :: String
, directory :: FilePath , directory :: FilePath
@ -28,29 +30,27 @@ args = Args
( long "header" ( long "header"
<> short 'H' <> short 'H'
<> value "" <> value ""
<> help "File with header text" ) <> help "Header text" )
<*> switch <*> switch
( long "verbose" ( long "verbose"
<> short 'v' <> short 'v'
<> help "Verbose mode") <> help "Verbose mode")
--mapM_ putStrLn =<< getDirectoryContents =<< getEnv "FIETS"
main :: IO () main :: IO ()
main = parseArgs =<< execParser opts main = parseArgs =<< execParser opts
where where
opts = info ( args <**> helper) opts = info ( args <**> helper)
( fullDesc ( fullDesc
<> progDesc "Generate gemini page index" <> progDesc "Generate gemini page index"
<> header "fucking kill me") <> header "Generate a gemini page index")
parseArgs :: Args -> IO() parseArgs :: Args -> IO()
parseArgs (Args t d h False) = do parseArgs (Args t d h False) = do
putStr success
putStrLn $ "# " ++ t putStrLn $ "# " ++ t
putStrLn =<< readFile h putStrLn h
mkIndex =<< getDirectoryContents d mkIndex =<< getDirectoryContents d
parseArgs _ = putStrLn "fiets" parseArgs _ = putStrLn "fiets"
mkIndex :: [String] -> IO () mkIndex :: [String] -> IO ()
--mkIndex = mapM_ (putStrLn . ("=> " ++))
mkIndex = mapM_ (putStrLn . ("=> " ++)) . filter (isSuffixOf ".gmi") mkIndex = mapM_ (putStrLn . ("=> " ++)) . filter (isSuffixOf ".gmi")