Cleanup
This commit is contained in:
parent
0a909da52f
commit
2fbde34568
21
app/Main.hs
21
app/Main.hs
|
@ -12,7 +12,7 @@ data Args = Args
|
||||||
{ title :: String
|
{ title :: String
|
||||||
, directory :: FilePath
|
, directory :: FilePath
|
||||||
, fileHead :: FilePath
|
, fileHead :: FilePath
|
||||||
, verbose :: Bool
|
--, verbose :: Bool
|
||||||
, names :: Bool
|
, names :: Bool
|
||||||
, cgi :: Bool
|
, cgi :: Bool
|
||||||
, back :: Bool
|
, back :: Bool
|
||||||
|
@ -23,7 +23,7 @@ args = Args
|
||||||
<$> strOption ( long "title" <> short 't' <> value "Title Left Blank" <> help "Document title" )
|
<$> strOption ( long "title" <> short 't' <> value "Title Left Blank" <> help "Document title" )
|
||||||
<*> strOption ( long "directory" <> short 'd' <> value "./" <> help "Directory to parse" )
|
<*> strOption ( long "directory" <> short 'd' <> value "./" <> help "Directory to parse" )
|
||||||
<*> strOption ( long "header" <> short 'H' <> value "" <> help "Header text" )
|
<*> strOption ( long "header" <> short 'H' <> value "" <> help "Header text" )
|
||||||
<*> switch ( long "verbose" <> short 'v' <> help "Verbose mode")
|
-- <*> 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 "names" <> short 'n' <> help "Generate link names based on first of each document" )
|
||||||
<*> switch ( long "cgi" <> help "Output gemini file header")
|
<*> switch ( long "cgi" <> help "Output gemini file header")
|
||||||
<*> switch ( long "back" <> help "Print 'return to dir' url")
|
<*> switch ( long "back" <> help "Print 'return to dir' url")
|
||||||
|
@ -37,7 +37,8 @@ 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 dir h v r c b) = do
|
--parseArgs (Args t dir h v n c b) = do
|
||||||
|
parseArgs (Args t dir h n c b) = do
|
||||||
if c
|
if c
|
||||||
then do print CgiSuccess
|
then do print CgiSuccess
|
||||||
putStrLn $ "# " ++ t
|
putStrLn $ "# " ++ t
|
||||||
|
@ -48,18 +49,20 @@ parseArgs (Args t dir h v r c b) = do
|
||||||
else putStr "\n"
|
else putStr "\n"
|
||||||
|
|
||||||
if b then do
|
if b then do
|
||||||
mapM_ (mkIndex r dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
|
mapM_ (mkIndex n dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
|
||||||
putStr "\n"
|
putStr "\n"
|
||||||
putStrLn "=> .. "
|
putStrLn "=> .. "
|
||||||
else mapM_ (mkIndex r dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
|
else mapM_ (mkIndex n dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
|
||||||
|
|
||||||
mkIndex :: Bool -> FilePath -> FilePath -> IO ()
|
mkIndex :: Bool -> FilePath -> FilePath -> IO ()
|
||||||
|
|
||||||
mkIndex False d l = putStrLn $ "=> " ++ path
|
mkIndex False d f = putStrLn $ "=> " ++ path d
|
||||||
where path = d++"/"++l
|
where path s
|
||||||
|
| s == "./" = f
|
||||||
|
| otherwise = s++"/"++f
|
||||||
|
|
||||||
mkIndex True d l =
|
mkIndex True d f =
|
||||||
let path = d ++ "/" ++ l
|
let path = d ++ "/" ++ f
|
||||||
trim s
|
trim s
|
||||||
| length s >= 8 = appendDots . unwords . take 8 . cleanString $ s
|
| length s >= 8 = appendDots . unwords . take 8 . cleanString $ s
|
||||||
| otherwise = unwords . cleanString $ s
|
| otherwise = unwords . cleanString $ s
|
||||||
|
|
Loading…
Reference in a new issue