From ce3a061a737bd533a0b3588a65837ff561cb08e1 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 5 Feb 2019 11:31:42 +0100 Subject: [PATCH] Add a JS script to be copied in the project and loaded in the interface --- hablo.cabal | 3 +++ js/main.js | 3 +++ src/Dom.hs | 1 + src/JS.hs | 18 ++++++++++++++++++ src/Main.hs | 2 ++ 5 files changed, 27 insertions(+) create mode 100644 js/main.js create mode 100644 src/JS.hs diff --git a/hablo.cabal b/hablo.cabal index dce3ccb..e68570c 100644 --- a/hablo.cabal +++ b/hablo.cabal @@ -15,6 +15,7 @@ maintainer: tissevert+devel@marvid.fr -- copyright: category: Web extra-source-files: CHANGELOG.md +data-files: js/main.js executable hablo main-is: Main.hs @@ -24,7 +25,9 @@ executable hablo , Blog , Dom , HTML + , JS , JSON + , Paths_hablo -- other-extensions: build-depends: aeson , base ^>=4.12.0.0 diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..973d74f --- /dev/null +++ b/js/main.js @@ -0,0 +1,3 @@ +window.addEventListener('load', function() { + console.log("Hablo loaded"); +}); diff --git a/src/Dom.hs b/src/Dom.hs index b05bbfb..1009d21 100644 --- a/src/Dom.hs +++ b/src/Dom.hs @@ -64,6 +64,7 @@ page aPage = title_ . toHtml =<< Blog.get name script_ [src_ "/UnitJS/async.js"] empty script_ [src_ "/UnitJS/dom.js"] empty + script_ [src_ "/js/main.js"] empty maybe (toHtml empty) toHtmlRaw =<< Blog.get customHead ) body_ (do diff --git a/src/JS.hs b/src/JS.hs new file mode 100644 index 0000000..435129a --- /dev/null +++ b/src/JS.hs @@ -0,0 +1,18 @@ +module JS ( + install + ) where + +import Blog (Blog(..)) +import qualified Blog (get) +import Control.Monad.IO.Class (MonadIO(..)) +import Control.Monad.Reader (ReaderT) +import Paths_hablo (getDataFileName) +import System.Directory (copyFile, createDirectoryIfMissing) +import System.FilePath (()) + +install :: ReaderT Blog IO () +install = do + source <- liftIO $ getDataFileName "js/main.js" + destinationDir <- ( "js") <$> Blog.get root + liftIO $ createDirectoryIfMissing False destinationDir + liftIO $ copyFile source (destinationDir "main.js") diff --git a/src/Main.hs b/src/Main.hs index 58c5402..775acb3 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -3,6 +3,7 @@ module Main where import qualified Arguments (get) import qualified Blog (build) import qualified HTML (generate) +import qualified JS (install) import qualified JSON (generate) import Control.Monad.Reader (runReaderT) @@ -13,4 +14,5 @@ main = do >>= runReaderT (do HTML.generate JSON.generate + JS.install )