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