Added 'return' link option and check if last char is dot
This commit is contained in:
parent
6e0fa21ba9
commit
397b8764fd
34
app/Main.hs
34
app/Main.hs
|
@ -15,6 +15,7 @@ data Args = Args
|
|||
, verbose :: Bool
|
||||
, names :: Bool
|
||||
, cgi :: Bool
|
||||
, back :: Bool
|
||||
}
|
||||
|
||||
args :: Parser Args
|
||||
|
@ -25,6 +26,7 @@ args = Args
|
|||
<*> 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")
|
||||
<*> switch ( long "back" <> help "Print 'return to dir' url")
|
||||
|
||||
main :: IO ()
|
||||
main = parseArgs =<< execParser opts
|
||||
|
@ -35,7 +37,7 @@ main = parseArgs =<< execParser opts
|
|||
<> header "Generate a gemini page index")
|
||||
|
||||
parseArgs :: Args -> IO()
|
||||
parseArgs (Args t dir h v r c) = do
|
||||
parseArgs (Args t dir h v r c b) = do
|
||||
if c
|
||||
then do print CgiSuccess
|
||||
putStrLn $ "# " ++ t
|
||||
|
@ -45,19 +47,29 @@ parseArgs (Args t dir h v r c) = do
|
|||
then putStr $ "\n" ++ h ++ "\n\n"
|
||||
else putStr "\n"
|
||||
|
||||
mapM_ (mkIndex r dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
|
||||
if b then do
|
||||
mapM_ (mkIndex r dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
|
||||
putStr "\n"
|
||||
putStrLn "=> ../ "
|
||||
else mapM_ (mkIndex r dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir
|
||||
|
||||
mkIndex :: Bool -> FilePath -> FilePath -> IO ()
|
||||
|
||||
mkIndex False d l = putStrLn $ "=> " ++ path
|
||||
where path = d++"/"++l
|
||||
|
||||
mkIndex True d l = do
|
||||
line <- trim . words . head . lines <$> readFile path
|
||||
putStrLn $ "=> " ++ path ++ " " ++ line
|
||||
where path = d++"/"++l
|
||||
trim s
|
||||
| length s >= 8 = (++ "...") . unwords . take 8 . cleanString $ s
|
||||
| otherwise = unwords . cleanString $ s
|
||||
-- remove all '#' signs and any potential resulting empty lists
|
||||
where cleanString = filter(/="") . map (dropWhile (=='#'))
|
||||
mkIndex True d l =
|
||||
let path = d ++ "/" ++ l
|
||||
trim s
|
||||
| length s >= 8 = appendDots . unwords . take 8 . cleanString $ s
|
||||
| otherwise = unwords . cleanString $ s
|
||||
where
|
||||
-- remove all '#' signs and any potential resulting empty lists
|
||||
cleanString = filter (/= "") . map (dropWhile (== '#'))
|
||||
-- in case the last character is a dot, remove it
|
||||
appendDots name
|
||||
| last name == '.' = (++ "...") . init $ name
|
||||
| otherwise = name
|
||||
in do
|
||||
line <- trim . words . head . lines <$> readFile path
|
||||
putStrLn $ "=> " ++ path ++ " " ++ line
|
||||
|
|
Loading…
Reference in a new issue