Add a JS script to be copied in the project and loaded in the interface

This commit is contained in:
Tissevert 2019-02-05 11:31:42 +01:00
parent 9d22da4c8b
commit ce3a061a73
5 changed files with 27 additions and 0 deletions

View file

@ -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

3
js/main.js Normal file
View file

@ -0,0 +1,3 @@
window.addEventListener('load', function() {
console.log("Hablo loaded");
});

View file

@ -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

18
src/JS.hs Normal file
View file

@ -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")

View file

@ -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
)