summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2023-05-13 20:48:37 +0100
committerYann Herklotz <git@yannherklotz.com>2023-05-13 20:48:37 +0100
commit1cdedbb50ed5ff9aea4a5ecf78e512dc52cc03af (patch)
treeff231a5d04bd5d81611b60be715bd70b99da0c8a
parent6b797b52d65e0b174205bb12bc5075fed1825724 (diff)
downloadzk-visual-1cdedbb50ed5ff9aea4a5ecf78e512dc52cc03af.tar.gz
zk-visual-1cdedbb50ed5ff9aea4a5ecf78e512dc52cc03af.zip
Add a command line interface
-rw-r--r--org-zk.cabal1
-rw-r--r--src/Main.hs55
-rw-r--r--src/Zettel/Transclusion.hs4
3 files changed, 49 insertions, 11 deletions
diff --git a/org-zk.cabal b/org-zk.cabal
index bca2ac2..a542c7a 100644
--- a/org-zk.cabal
+++ b/org-zk.cabal
@@ -35,6 +35,7 @@ executable org-zk
, with-utf8
, directory
, filepath
+ , cmdargs
mixins:
base hiding (Prelude),
diff --git a/src/Main.hs b/src/Main.hs
index 1e1094a..dd77a2a 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE DeriveDataTypeable #-}
+
module Main where
-- import Data.Char (isAlphaNum, isLetter, isNumber)
@@ -18,6 +20,8 @@ module Main where
-- import Text.Pandoc.Walk (walkM, walk)
-- import qualified Data.ByteString.Lazy as B
-- import System.Directory (createDirectoryIfMissing)
+
+import System.Console.CmdArgs.Implicit
import Zettel
-- data HeaderState = HeaderState
@@ -199,19 +203,48 @@ import Zettel
-- writeFileText ("test/content/" <> chunkPath c) text
--
+data Options = Options
+ { org :: [FilePath],
+ bibliography :: Maybe FilePath,
+ csl :: Maybe FilePath,
+ index :: Maybe FilePath,
+ output :: FilePath
+ }
+ deriving (Show, Data, Typeable)
+
+options :: Options
+options =
+ Options
+ { org = def &= args &= typ "FILES...",
+ output = def &= name "o" &= help "Output directory" &= typDir,
+ bibliography =
+ def
+ &= name "b"
+ &= help "Bibliography file path (default: references.bib)"
+ &= typFile
+ &= opt (Just ("references.bib" :: FilePath)),
+ csl =
+ def
+ &= name "c"
+ &= help "Csl file path (default: ieee.csl)"
+ &= typFile
+ &= opt (Just ("ieee.csl" :: FilePath)),
+ index =
+ def
+ &= name "i"
+ &= help "Index file path"
+ &= typFile
+ }
+ &= summary "org-zk v0.1.0, (C) 2023 Yann Herklotz"
+ &= program "org-zk"
+ &= verbosity
+
main :: IO ()
main = do
- let fl =
- [ (3, "/Users/ymherklotz/Dropbox/zk/verification.org"),
- (4, "/Users/ymherklotz/Dropbox/zk/mathematics.org"),
- (1, "/Users/ymherklotz/Dropbox/zk/hls.org"),
- (2, "/Users/ymherklotz/Dropbox/zk/computing.org"),
- (5, "/Users/ymherklotz/Dropbox/zk/hardware.org"),
- (6, "/Users/ymherklotz/Dropbox/zk/general.org")
- ]
- graph' <- parseZettelKasten fl
+ zkOpts <- cmdArgs options
+ let fl = org zkOpts
+ graph' <- parseZettelKasten $ zip [1 ..] fl
let graph = transcludeMdAll graph'
let linkedGraph = linkAll graph
let wrappedGraph = wrapZettelGraph linkedGraph
- renderZettelGraphFile "../zk-web/content/zettel" wrappedGraph
- return ()
+ renderZettelGraphFile (output zkOpts) wrappedGraph
diff --git a/src/Zettel/Transclusion.hs b/src/Zettel/Transclusion.hs
index 617a475..63e1271 100644
--- a/src/Zettel/Transclusion.hs
+++ b/src/Zettel/Transclusion.hs
@@ -9,6 +9,10 @@ import Text.Pandoc.Walk (walk, query)
import Zettel.Common
import Zettel.Types
+between :: Char -> Char -> Text -> Text
+between c1 c2 t =
+ T.drop 1 . T.takeWhile (c2 /=) $ T.dropWhile (c1 /=) t
+
attrValue :: Text -> Text -> Maybe Text
attrValue t v = viaNonEmpty head . drop 1 . dropWhile (/= v) $ T.words t