diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-11 22:10:32 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-11 22:10:32 +0200 |
commit | 71b19ca69a95cfb8025eef08d66c2280098a34c5 (patch) | |
tree | 1146e10b965a630f17596a2fa8258fe76a8762d3 | |
parent | Handlingar to HTML work. (diff) | |
download | vimwiki-scripts-71b19ca69a95cfb8025eef08d66c2280098a34c5.tar.gz vimwiki-scripts-71b19ca69a95cfb8025eef08d66c2280098a34c5.tar.xz |
Got HTML-handlingar working.
-rw-r--r-- | hs/html.template | 21 | ||||
-rw-r--r-- | hs/src/Handlingar/HtmlOutput.hs | 38 |
2 files changed, 55 insertions, 4 deletions
diff --git a/hs/html.template b/hs/html.template new file mode 100644 index 0000000..c81684e --- /dev/null +++ b/hs/html.template @@ -0,0 +1,21 @@ +<use file="../../../base.xml"> +<style> +code { + white-space: pre; + font-family: monospace; +} +object { + width: 100%; + min-height: 60ch; + height: 100%; +} +</style> +<lyspage +title="Höstmöte 2023" + lang="sv" + +<section class="feed"> +<card h="Höstmöte 2023"> +$body$ +</card> +</section> diff --git a/hs/src/Handlingar/HtmlOutput.hs b/hs/src/Handlingar/HtmlOutput.hs index 29121ba..320df19 100644 --- a/hs/src/Handlingar/HtmlOutput.hs +++ b/hs/src/Handlingar/HtmlOutput.hs @@ -22,6 +22,13 @@ import System.Directory (copyFile) import System.Posix.Directory (changeWorkingDirectory, getWorkingDirectory) import Control.Exception (catch) import Data.Map.Strict qualified as Map +import Text.DocTemplates (compileTemplateFile) +import Text.Pandoc.Templates ( Template(..), getTemplate, renderTemplate, WithDefaultPartials(..)) +import Text.DocTemplates () +import Text.Pandoc (readVimwiki, WriterOptions(writerTemplate, writerListings, writerVariables), PandocIO) +import System.Process (createProcess, shell, CreateProcess(cwd), waitForProcess) +import System.Directory (makeAbsolute, createDirectoryIfMissing, copyFile) +import System.FilePath (takeBaseName) import Prelude hiding (writeFile) @@ -37,7 +44,16 @@ handleAppendix ops source_blocks (link_text, _, target) = do _ -> liftIO $ copyFile (unpack . T.drop 5 $ target) (destination ops </> (unpack . sourceToTarget' $ target)) -- liftIO $ catch (copyFile (unpack target) (destination ops </> (unpack . sourceToTarget' $ target))) (\_ -> (copyFile (unpack target <> ".wiki") (destination ops </> (unpack . sourceToTarget' $ target)))) - out <- writeHtml5String (def) (Pandoc (Meta Map.empty) xs) + liftIO $ print xs + -- template' <- getTemplate "html.template" + -- res' <- compileTemplate "html.template" template' + res' <- liftIO $ compileTemplateFile "/home/hugo/code/vimwiki-scripts/hs/html.template" + let res = case res' of + Left _ -> Nothing + Right x -> Just x + liftIO . putStrLn $ "template: " ++ show res + -- let template = renderTemplate templateData + out <- writeHtml5String (def { writerTemplate = res }) (Pandoc (Meta Map.empty) xs) liftIO $ writeFile (destination ops </> (unpack . sourceToTarget $ target)) (out) -- (pack . show $ xs) @@ -65,9 +81,19 @@ rewriteLinkHtml x = return x -- TODO this is probably where we should create the included files handleFileHtml :: FilePath -> String -> PandocIO (Maybe [Block]) -handleFileHtml fname ".tex" = return . Just $ [] +handleFileHtml fname ".tex" = do + aname <- liftIO $ makeAbsolute fname + let dest = "/tmp/vimwiki-script/" ++ (takeBaseName aname) + liftIO $ createDirectoryIfMissing True dest + liftIO (copyFile aname $ dest ++ "/doc.tex") + (_, _, _, handle) <- liftIO $ createProcess ((shell "latexmk -pdf doc") { cwd = Just dest }) + liftIO $ waitForProcess handle + handleFileHtml (dest ++ "/doc.pdf") ".pdf" handleFileHtml fname ".pdf" = return . Just $ [ Plain [ RawInline (Format "html") ("<object type=\"application/pdf\" data=\"" <> (sourceToTarget' . pack $ fname) <> "\">PDF Failed loading</object>") ] ] -handleFileHtml fname _ = return . Just $ [] +handleFileHtml fname _ = do + dat <- liftIO $ readFile fname + return . Just $ [ Plain [ Code ("", [], []) (pack dat) ]] + handleHtml :: Text -> String -> FilePath -> PandocIO () handleHtml source_text heading destination = do @@ -89,5 +115,9 @@ handleHtml source_text heading destination = do liftIO $ putStrLn $ "apx: " ++ show apx let content = Pandoc meta bs - result <- writeHtml5String (def) content + res' <- liftIO $ compileTemplateFile "/home/hugo/code/vimwiki-scripts/hs/html.template" + let res = case res' of + Left _ -> Nothing + Right x -> Just x + result <- writeHtml5String (def { writerTemplate = res }) content liftIO $ writeFile (destination </> "index.html") result |