diff --git a/share/js/main.js b/share/js/main.js index 76f9ec3..4659256 100644 --- a/share/js/main.js +++ b/share/js/main.js @@ -3,7 +3,7 @@ window.addEventListener('load', function() { var cache = unitJS.Cache(); var dom = unitJS.Dom(); var fun = unitJS.Fun(); - var md = new Remarkable({html: true}); + var md = new Remarkable(remarkableConfig); md.block.ruler.enable(['footnote']); var comments = Comments({async: async, cache: cache, dom: dom}); var domRenderer = DomRenderer({comments: comments, fun: fun, md: md, dom: dom}); diff --git a/src/Arguments.hs b/src/Arguments.hs index 3b6b447..a37dbde 100644 --- a/src/Arguments.hs +++ b/src/Arguments.hs @@ -23,6 +23,7 @@ data Arguments = BlogConfig { , pagesPath :: Maybe FilePath , previewArticlesCount :: Int , previewLinesCount :: Int + , remarkableConfig :: Maybe FilePath , wording :: Maybe FilePath } | Version @@ -41,35 +42,37 @@ blogConfig :: Parser Arguments blogConfig = BlogConfig <$> argument filePath (value "." <> metavar "INPUT_DIR") <*> Optparse.option filePath ( - metavar "ARTICLES_PATH" + metavar "DIRECTORY" <> value "articles" <> short 'a' <> long "articles" - <> help "name of the directory containing the articles within INPUT_DIR" + <> help "relative path to the directory containing the articles within INPUT_DIR" ) - <*> option filePath 'b' "banner" "BANNER_PATH" "path to the file to use for the blog's banner" - <*> option filePath 'c' "card-image" "CARD_IMAGE" "path to the image to use for the blog's card" - <*> option filePath 'C' "comments-at" "INSTANCE_URL" "url of the instance where comments are stored" - <*> option filePath 'f' "favicon" "FAVICON" "path to the image to use for the blog's favicon" - <*> option filePath 'H' "head" "HEAD_PATH" "path to the file to add in the blog's head" + <*> option filePath 'b' "banner" "FILE" "path to the file to use for the blog's banner" + <*> option filePath 'c' "card-image" "FILE" "relative path to the image to use for the blog's card" + <*> option filePath 'C' "comments-at" "URL" "url of the instance where comments are stored" + <*> option filePath 'f' "favicon" "FILE" "path to the image to use for the blog's favicon" + <*> option filePath 'H' "head" "FILE" "path to the file to add in the blog's head" <*> option str 'n' "name" "BLOG_NAME" "name of the blog" <*> option filePath 'p' "pages" - "PAGES_PATH" "name of the directory containing the pages within INPUT_DIR" + "DIRECTORY" "relative path to the directory containing the pages within INPUT_DIR" <*> Optparse.option auto ( - metavar "PREVIEW_ARTICLES_COUNT" + metavar "INTEGER" <> value 3 <> short 'A' <> long "preview-articles" <> help "number of articles listed on the page of each category" ) <*> Optparse.option auto ( - metavar "PREVIEW_LINES_COUNT" + metavar "INTEGER" <> value 10 <> short 'L' <> long "preview-lines" <> help "number of lines to display in articles preview" ) - <*> option filePath 'w' "wording" "WORDING" "path to the file containing the wording to use" + <*> option filePath 'r' "remarkable-config" "FILE" + "path to a file containing a custom RemarkableJS configuration" + <*> option filePath 'w' "wording" "FILE" "path to the file containing the wording to use" version :: Parser Arguments version = flag' Version ( diff --git a/src/Blog/Path.hs b/src/Blog/Path.hs index 396f5e9..362d61f 100644 --- a/src/Blog/Path.hs +++ b/src/Blog/Path.hs @@ -12,6 +12,7 @@ data Path = Path { articlesPath :: FilePath , commentsAt :: Maybe String , pagesPath :: Maybe FilePath + , remarkableConfig :: Maybe FilePath , root :: FilePath } @@ -19,7 +20,10 @@ build :: Arguments -> IO Path build arguments = do articlesPath <- filePath . Dir $ Arguments.articlesPath arguments pagesPath <- mapM (filePath . Dir) $ Arguments.pagesPath arguments + remarkableConfig <- mapM (filePath . File) $ Arguments.remarkableConfig arguments root <- absolute . Dir $ Arguments.sourceDir arguments return $ Path { - articlesPath, commentsAt = Arguments.commentsAt arguments, pagesPath, root + articlesPath, commentsAt, pagesPath, remarkableConfig, root } + where + commentsAt = Arguments.commentsAt arguments diff --git a/src/JS.hs b/src/JS.hs index 1fa7336..22f6372 100644 --- a/src/JS.hs +++ b/src/JS.hs @@ -8,6 +8,7 @@ import qualified Blog (get) import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.Reader (ReaderT) import Data.ByteString.Lazy (ByteString, concat, readFile, writeFile) +import Data.ByteString.Lazy.Char8 (pack) import qualified Files (find) import JSON (exportBlog) import Paths_hablo (getDataDir) @@ -22,12 +23,18 @@ compile sources = concat (header:sources ++ [footer]) header = "(function() {\n" footer = "})();" +var :: (String, ByteString) -> ByteString +var (varName, content) = concat ["var ", pack varName, " = ", content, ";\n"] + generate :: ReaderT Blog IO () generate = do destinationDir <- ( "js") <$> (Blog.get $path.$root) blogJSON <- exportBlog + remarkablePath <- Blog.get $path.$remarkableConfig liftIO $ do + remarkableJSON <- maybe (return "{html: true}") readFile remarkablePath + let jsVars = var <$> [("blog", blogJSON), ("remarkableConfig", remarkableJSON)] jsFiles <- ( "js") <$> getDataDir >>= Files.find jsCode <- mapM readFile jsFiles createDirectoryIfMissing False destinationDir - writeFile (destinationDir "hablo.js") $ compile ("var blog = ":blogJSON:";":jsCode ) + writeFile (destinationDir "hablo.js") $ compile (jsVars ++ jsCode )