Formatting

This commit is contained in:
Nox Sluijtman 2023-07-31 16:09:45 +02:00
parent 1cda324ad2
commit f9325d02c9

View file

@ -4,46 +4,27 @@ import System.Directory
import Options.Applicative
import Data.List
success :: String
success = "20 text/gemini; lang=en; charset=utf-8\r\n"
data CgiState = CgiSuccess
instance Show CgiState where
show CgiSuccess = "20 text/gemini; lang=en; charset=utf-8\r"
data Args = Args
{ title :: String
, directory :: FilePath
, fileHead :: FilePath
, verbose :: Bool
, refs :: Bool
, names :: Bool
, cgi :: Bool
}
args :: Parser Args
args = Args
<$> strOption
( long "title"
<> short 't'
<> value "Title Left Blank"
<> help "Document title" )
<*> strOption
( long "directory"
<> short 'd'
<> value "./"
<> help "Directory to parse" )
<*> strOption
( long "header"
<> short 'H'
<> value ""
<> help "Header text" )
<*> switch
( long "verbose"
<> short 'v'
<> help "Verbose mode")
<*> switch
( long "references"
<> short 'R'
<> help "Generate link reference based on first line of document" )
<*> switch
( long "cgi"
<> help "Output gemini file header")
<$> strOption ( long "title" <> short 't' <> value "Title Left Blank" <> help "Document title" )
<*> strOption ( long "directory" <> short 'd' <> value "./" <> help "Directory to parse" )
<*> strOption ( long "header" <> short 'H' <> value "" <> help "Header text" )
<*> switch ( long "verbose" <> short 'v' <> help "Verbose mode")
<*> switch ( long "names" <> short 'n' <> help "Generate link names based on first of each document" )
<*> switch ( long "cgi" <> help "Output gemini file header")
main :: IO ()
main = parseArgs =<< execParser opts
@ -56,18 +37,21 @@ main = parseArgs =<< execParser opts
parseArgs :: Args -> IO()
parseArgs (Args t dir h v r c) = do
if c then do
putStr success
print CgiSuccess
putStrLn $ "# " ++ t
else putStrLn $ "# " ++ t
if not (null h)
then putStr $ "\n\n" ++ h ++ "\n\n"
then putStr $ "\n" ++ h ++ "\n\n"
else putStr "\n"
mapM_ (mkIndex r dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
mkIndex :: Bool -> FilePath -> FilePath -> IO ()
mkIndex True d l = do
line <- readFile $ d++"/"++l
putStrLn $ "=> " ++ l ++ " " ++ (head . lines $ line)
mkIndex False d l = putStrLn $ "=> " ++ d ++ "/" ++ l
putStrLn $ "=> " ++ path ++ (head . lines $ line)
where path = d++"/"++l++" "
mkIndex False d l = putStrLn $ "=> " ++ path
where path = d++"/"++l
--compose = (++) <$> ("=> " ++) <*> (show . length) <*> (head . lines =<< readFile)