diff --git a/hakyll-bootstrap/.gitignore b/hakyll-bootstrap/.gitignore index 19df1ab2cf90958cce1407da682eef11fc119c9d..eb5857ba41b396dbde6fca59376a10a71234ff85 100644 --- a/hakyll-bootstrap/.gitignore +++ b/hakyll-bootstrap/.gitignore @@ -1,4 +1,3 @@ -dist cabal-dev *.o *.hi diff --git a/hakyll-bootstrap/Main.hs b/hakyll-bootstrap/Main.hs index 6c056540fbb37f4ddaafa32283282f3ee1e588af..ecdbc37d5f21634c35443327acc3720ac18a9184 100644 --- a/hakyll-bootstrap/Main.hs +++ b/hakyll-bootstrap/Main.hs @@ -12,16 +12,195 @@ module Main where {-# LANGUAGE OverloadedStrings #-} -import Data.Monoid (mappend) import Hakyll -import Text.Pandoc -import qualified Data.Map as M +import Text.Pandoc as Pandoc +import qualified Data.Text as T +import qualified System.Process as Process +import System.FilePath (replaceExtension, takeDirectory) import Data.Maybe (isJust) -import Text.Pandoc.Highlighting import Hakyll.Images ( loadImage , scaleImageCompiler ) +-------------------------------------------------------------------------------- +-- | Entry point +main :: IO () +main = hakyllWith cfg $ do + -- Resize images + match "img/thumbnails/**.png" $ do + route idRoute + compile $ loadImage + >>= scaleImageCompiler 140 140 + + match "img/heads/**.png" $ do + route idRoute + compile $ loadImage + >>= scaleImageCompiler 256 256 + + match "img/large/**.png" $ do + route idRoute + compile $ loadImage + >>= scaleImageCompiler 900 262 + + -- copying stuff + match ("fonts/*" + .||. "img/*" + .||. "img/*/**.png" + .||. "css/*" + .||. "js/*" + .||. "reveal.js/dist/**" + .||. "reveal.js/plugin/**" + .||. "cours/math_tech_info/figs/*" + .||. "cours/math_tech_info/cours.pdf" + .||. "cours/isc_physics/cours.pdf" + .||. "cours/isc_physics/figs/*") $ do + route idRoute + compile $ copyFileCompiler + + -- Phys app posts + match "cours/isc_physics/*.markdown" $ do + route $ setExtension "html" + compile $ pandocCrossrefNumberingCompiler + >>= loadAndApplyTemplate "templates/class.html" postCtx + >>= relativizeUrls + + -- Phys app post list + create ["phys_app.html"] $ do + route idRoute + compile $ do + posts <- recentFirst =<< loadAll ("cours/isc_physics/*.markdown" .&&. hasNoVersion) + makeItem "" + >>= loadAndApplyTemplate "templates/archive.html" (courseCtx posts "Physique appliquée" "cours/isc_physics/cours.pdf") + >>= relativizeUrls + + -- Math Tech Info posts + match "cours/math_tech_info/*.markdown" $ do + route $ setExtension "html" + compile $ pandocCrossrefNumberingCompiler + >>= loadAndApplyTemplate "templates/class.html" postCtx + >>= relativizeUrls + + -- Math Tech Info posts in PDF. Producing the .pdf + -- PDF produced but putting it into a list not... + -- match "cours/math_tech_info/1_Rappel.markdown" $ version "pdf" $ do + -- route $ setExtension "pdf" + -- compile $ do getResourceBody + -- >>= readPandoc + -- >>= writeXeTex + -- >>= loadAndApplyTemplate "templates/default.latex" defaultContext + -- >>= xelatex + + -- Math Tech Info post list + create ["math_tech_info.html"] $ do + route idRoute + compile $ do + posts <- recentFirst =<< loadAll ("cours/math_tech_info/*.markdown" .&&. hasNoVersion) + makeItem "" + >>= loadAndApplyTemplate "templates/archive.html" (courseCtx posts "Mathématiques en technologie de l'information" "cours/math_tech_info/cours.pdf") + >>= relativizeUrls + + -- Phys app posts + match "cours/prog_seq/base_1.md" $ do + route $ setExtension "html" + compile $ pandocRevealCompiler + >>= loadAndApplyTemplate "templates/reveal.html" postCtx + >>= relativizeUrls + + -- Phys app post list + create ["prog_seq.html"] $ do + route idRoute + compile $ do + posts <- recentFirst =<< loadAll ("cours/prog_seq/base_1.md" .&&. hasNoVersion) + makeItem "" + >>= loadAndApplyTemplate "templates/archive.html" (courseCtx posts "Programmation séquentielle" "cours/isc_physics/cours.pdf") + >>= relativizeUrls + + + -- Index + match "index.html" $ do + route idRoute + compile $ do + posts <- recentFirst =<< loadAll "posts/*" + getResourceBody + >>= applyAsTemplate (indexCtx posts) + >>= relativizeUrls + + -- Read templates + match "templates/*" $ compile templateCompiler + + -- Used to compile to PDF + -- where + -- writeXeTex :: Item Pandoc.Pandoc -> Compiler (Item String) + -- writeXeTex = traverse $ \pandoc -> + -- case Pandoc.runPure (Pandoc.writeLaTeX Pandoc.def pandoc) of + -- Left err -> fail $ show err + -- Right x -> return (T.unpack x) + + + +-- pages :: Rules () +-- pages = do +-- match "pages/*" $ do +-- route $ setExtension "html" +-- compile $ getResourceBody +-- >>= loadAndApplyTemplate "templates/page.html" postCtx +-- >>= relativizeUrls + +-- research :: Rules () +-- research = do +-- create ["research_projects.html"] $ do +-- route idRoute +-- compile $ do +-- posts <- recentFirst =<< loadAll "posts/research/*" +-- makeItem "" +-- >>= loadAndApplyTemplate "templates/archive.html" (researchCtx posts) +-- >>= relativizeUrls + +-- bachelor :: Rules () +-- bachelor = do +-- create ["bachelor_projects.html"] $ do +-- route idRoute +-- compile $ do +-- posts <- recentFirst =<< loadAll "posts/bachelor/*" +-- makeItem "" +-- >>= loadAndApplyTemplate "templates/archive.html" (bachelorCtx posts) +-- >>= relativizeUrls + +-- cours_conc :: Rules () +-- cours_conc = do +-- match "cours/*" $ do +-- route $ setExtension "html" +-- -- compile $ myPandocCompiler +-- compile $ pandocCrossrefNumberingCompiler +-- >>= loadAndApplyTemplate "templates/post.html" postCtx +-- >>= relativizeUrls + +-- conc :: Rules () +-- conc = do +-- create ["prog_conc.html"] $ do +-- route idRoute +-- compile $ do +-- posts <- recentFirst =<< loadAll "cours/*" +-- makeItem "" +-- >>= loadAndApplyTemplate "templates/archive.html" (courseCtx posts "Programmation concurrente") +-- >>= relativizeUrls + + + +-- index :: Rules () +-- index = do +-- match "index.html" $ do +-- route idRoute +-- compile $ do +-- posts <- recentFirst =<< loadAll "posts/*" +-- getResourceBody +-- >>= applyAsTemplate (indexCtx posts) +-- >>= relativizeUrls + +-- templates :: Rules () +-- templates = match "templates/*" $ compile templateCompiler + + -------------------------------------------------------------------- -- Contexts -------------------------------------------------------------------- @@ -40,9 +219,10 @@ mathCtx = field "mathjax" $ \item -> do then "<script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML\"></script>" else "" -courseCtx posts title = +courseCtx posts title pdfurl = listField "posts" postCtx (return posts) `mappend` constField "title" title + `mappend` constField "pdfurl" pdfurl `mappend` defaultContext researchCtx posts = @@ -60,150 +240,6 @@ indexCtx posts = `mappend` constField "title" "Home" `mappend` defaultContext --------------------------------------------------------------------- --- Rules --------------------------------------------------------------------- - -static :: Rules () -static = do - match ("fonts/*" - .||. "img/*" - .||. "img/*/**.png" - .||. "css/*" - .||. "js/*" - .||. "cours/math_tech_info/figs/*" - .||. "cours/isc_physics/figs/*") $ do - route idRoute - compile $ copyFileCompiler - -resizeThumbnails :: Rules () -resizeThumbnails = do - match "img/thumbnails/**.png" $ do - route idRoute - compile $ loadImage - >>= scaleImageCompiler 140 140 - -resizeHeads :: Rules () -resizeHeads = do - match "img/heads/**.png" $ do - route idRoute - compile $ loadImage - >>= scaleImageCompiler 256 256 - -resizeLarge :: Rules () -resizeLarge = do - match "img/large/**.png" $ do - route idRoute - compile $ loadImage - >>= scaleImageCompiler 900 500 - -pages :: Rules () -pages = do - match "pages/*" $ do - route $ setExtension "html" - compile $ getResourceBody - >>= loadAndApplyTemplate "templates/page.html" postCtx - >>= relativizeUrls - -posts :: Rules () -posts = do - match "posts/*" $ do - route $ setExtension "html" - -- compile $ myPandocCompiler - compile $ bibtexCompiler - >>= loadAndApplyTemplate "templates/post.html" postCtx - >>= relativizeUrls - -research :: Rules () -research = do - create ["research_projects.html"] $ do - route idRoute - compile $ do - posts <- recentFirst =<< loadAll "posts/research/*" - makeItem "" - >>= loadAndApplyTemplate "templates/archive.html" (researchCtx posts) - >>= relativizeUrls - -bachelor :: Rules () -bachelor = do - create ["bachelor_projects.html"] $ do - route idRoute - compile $ do - posts <- recentFirst =<< loadAll "posts/bachelor/*" - makeItem "" - >>= loadAndApplyTemplate "templates/archive.html" (bachelorCtx posts) - >>= relativizeUrls - -cours_conc :: Rules () -cours_conc = do - match "cours/*" $ do - route $ setExtension "html" - -- compile $ myPandocCompiler - compile $ bibtexCompiler - >>= loadAndApplyTemplate "templates/post.html" postCtx - >>= relativizeUrls - -conc :: Rules () -conc = do - create ["prog_conc.html"] $ do - route idRoute - compile $ do - posts <- recentFirst =<< loadAll "cours/*" - makeItem "" - >>= loadAndApplyTemplate "templates/archive.html" (courseCtx posts "Programmation concurrente") - >>= relativizeUrls - -cours_mti :: Rules () -cours_mti = do - match "cours/math_tech_info/*.markdown" $ do - route $ setExtension "html" - -- compile $ myPandocCompiler - compile $ bibtexCompiler - >>= loadAndApplyTemplate "templates/class.html" postCtx - >>= relativizeUrls - -mti :: Rules () -mti = do - create ["math_tech_info.html"] $ do - route idRoute - compile $ do - posts <- recentFirst =<< loadAll "cours/math_tech_info/*" - makeItem "" - >>= loadAndApplyTemplate "templates/archive.html" (courseCtx posts "Mathématiques en technologie de l'information") - >>= relativizeUrls - -cours_phys_app :: Rules () -cours_phys_app = do - match "cours/isc_physics/*.markdown" $ do - route $ setExtension "html" - -- compile $ myPandocCompiler - compile $ bibtexCompiler - >>= loadAndApplyTemplate "templates/class.html" postCtx - >>= relativizeUrls - -phys_app :: Rules () -phys_app = do - create ["phys_app.html"] $ do - route idRoute - compile $ do - posts <- recentFirst =<< loadAll "cours/isc_physics/*" - makeItem "" - >>= loadAndApplyTemplate "templates/archive.html" (courseCtx posts "Physique appliquée") - >>= relativizeUrls - -index :: Rules () -index = do - match "index.html" $ do - route idRoute - compile $ do - posts <- recentFirst =<< loadAll "posts/*" - getResourceBody - >>= applyAsTemplate (indexCtx posts) - >>= relativizeUrls - -templates :: Rules () -templates = match "templates/*" $ compile templateCompiler - -------------------------------------------------------------------- -- Configuration -------------------------------------------------------------------- @@ -246,8 +282,8 @@ defaultPandocExtensions = in foldr enableExtension defaultExtensions extensions -bibtexCompiler :: Compiler (Item String) -bibtexCompiler = do +pandocCrossrefNumberingCompiler :: Compiler (Item String) +pandocCrossrefNumberingCompiler = do getResourceBody >>= withItemBody (unixFilter "pandoc" ["-F" , "pandoc-numbering" @@ -260,25 +296,60 @@ bibtexCompiler = do >>= return . writePandocWith pandocOptions + +pandocRevealCompiler :: Compiler (Item String) +pandocRevealCompiler = do + getResourceBody + >>= withItemBody (unixFilter "pandoc" ["-F" + , "pandoc-numbering" + , "-F" + , "pandoc-crossref" + , "-t" + , "revealjs" + , "-V" + , "revealjs-url=./reveal.js" + , "-V" + , "theme=white" + ]) + >>= readPandocWith defaultHakyllReaderOptions + >>= return . writePandocWith pandocOptions + +-------------------------------------------------------------------------------- +-- | Hacky. +-- xelatex :: Item String -> Compiler (Item TmpFile) +-- xelatex item = do +-- TmpFile texPath <- newTmpFile "xelatex.tex" +-- let tmpDir = takeDirectory texPath +-- pdfPath = replaceExtension texPath "pdf" + +-- unsafeCompiler $ do +-- writeFile texPath $ itemBody item +-- _ <- Process.system $ unwords ["xelatex", "-halt-on-error", +-- "-output-directory", tmpDir, texPath, ">/dev/null", "2>&1"] +-- return () + +-- makeItem $ TmpFile pdfPath + + cfg :: Configuration cfg = defaultConfiguration -main :: IO () -main = hakyllWith cfg $ do - pages - posts - cours_conc - conc - cours_mti - mti - cours_phys_app - phys_app - research - bachelor - index - templates - resizeThumbnails - resizeLarge - resizeHeads - static +-- main :: IO () +-- main = hakyllWith cfg $ do +-- pages +-- posts +-- cours_conc +-- conc +-- cours_mti +-- mti +-- cours_phys_app +-- phys_app +-- research +-- bachelor +-- index +-- templates +-- resizeThumbnails +-- resizeLarge +-- resizeHeads +-- static diff --git a/hakyll-bootstrap/Makefile b/hakyll-bootstrap/Makefile index 34ed7992599a9874c301deb518f8a0224951fb49..933556375bcf057489d1d32f8d3fa9d8a34f374d 100644 --- a/hakyll-bootstrap/Makefile +++ b/hakyll-bootstrap/Makefile @@ -1,7 +1,12 @@ watch: Main.hs cours/math_tech_info/*.md cours/isc_physics/*.md make hakyll_gen -C cours/math_tech_info make hakyll_gen -C cours/isc_physics - stack build && stack exec blog -- rebuild && stack exec blog -- watch + make -C cours/math_tech_info + make -C cours/isc_physics + stack build && stack exec blog -- build && stack exec blog -- watch + +build_revealjs: + cd reveal.js && npm install && npm run build && cd .. clean: rm -rf _cache _site diff --git a/hakyll-bootstrap/img/large/q_0_5.0000.png b/hakyll-bootstrap/img/large/q_0_5.0000.png index 832c0c57af58ca1f502cbe71d531a00a4ff1a07f..19802c9d599481f20bb5852952ea4fd1278a34f7 100644 Binary files a/hakyll-bootstrap/img/large/q_0_5.0000.png and b/hakyll-bootstrap/img/large/q_0_5.0000.png differ diff --git a/hakyll-bootstrap/templates/archive.html b/hakyll-bootstrap/templates/archive.html index 0ec1e09982b0094e2ac4fe255ff42dd3755bf71c..ccc167dd617646fb3f62db289d2a5ddad58d7c63 100644 --- a/hakyll-bootstrap/templates/archive.html +++ b/hakyll-bootstrap/templates/archive.html @@ -23,6 +23,8 @@ <div class="container"> <h1>$title$</h1> + <h3><a href="$pdfurl$">Le polycopié en entier [pdf]</a></h3> + <h2>Les chapitres</h2> <ul> $for(posts)$ <li>