Commit 8285c068 authored by Armin Bernstetter's avatar Armin Bernstetter
Browse files

Merge branch 'master' into 81-native-haskell-copy

parents 3d11d230 a0efe5ad
.DS_Store
*.prof
.stack-work/
.stack-work-profile/
.shake/
TAGS
public/
......
{-- Author: Henrik Tramberend <henrik@tramberend.de> --}
import Action
import Common
import Context
import Exception
import External
import Project
import Resources
import Shake
import Utilities
import Control.Exception
import Control.Lens ((^.))
import Control.Monad (when)
import Control.Monad.Extra
import Data.Aeson
......@@ -13,54 +19,28 @@ import Data.String ()
import Data.Version
import Development.Shake
import Development.Shake.FilePath
import Exception
import External
import GHC.Conc (numCapabilities)
import Project
import Resources
import System.Directory (createDirectoryIfMissing, createFileLink, removeFile)
import System.Environment.Blank
import System.FilePath ()
import Text.Groom
import qualified Text.Mustache as M ()
import Text.Pandoc
import Text.Pandoc.Definition
import Text.Printf ()
import Utilities
main :: IO ()
main = do
extractResources
dirs <- projectDirectories
directories <- projectDirectories
--
let projectDir = project dirs
let publicDir = public dirs
let supportDir = support dirs
let appDataDir = appData dirs
let serverPort = 8888
let serverUrl = "http://localhost:" ++ (show serverPort)
-- Find sources. These are formulated as actions in the Action mondad, such
-- that each new iteration rescans all possible source files.
let deckSourcesA = globA "**/*-deck.md"
let pageSourcesA = globA "**/*-page.md"
let allSourcesA = deckSourcesA <++> pageSourcesA
let allMarkdownA = globA "**/*.md"
let allImagesA = globA "**/*.png" <++> globA "**/*.jpg"
let metaA = globA "**/*-meta.yaml"
-- Calculate targets
let decksA = deckSourcesA >>= calcTargets ".md" ".html"
let decksPdfA = deckSourcesA >>= calcTargets ".md" ".pdf"
let handoutsA = deckSourcesA >>= calcTargets "-deck.md" "-handout.html"
let handoutsPdfA = deckSourcesA >>= calcTargets "-deck.md" "-handout.pdf"
let pagesA = pageSourcesA >>= calcTargets ".md" ".html"
let pagesPdfA = pageSourcesA >>= calcTargets ".md" ".pdf"
let indexSource = project dirs </> "index.md"
let index = publicDir </> "index.html"
let indexA = return [index] :: Action [FilePath]
let everythingA = decksA <++> handoutsA <++> pagesA
let everythingPdfA = decksPdfA <++> handoutsPdfA <++> pagesPdfA
let indexSource = (directories ^. project) </> "index.md"
let index = (directories ^. public) </> "index.html"
let cruft = ["index.md.generated", "log", "//.shake", "generated", "code"]
context <- makeActionContext dirs
runShakeInContext context (options projectDir) $
--
runDecker $
--
do
want ["html"]
......@@ -72,21 +52,24 @@ main = do
putNormal $ "pandoc-types version " ++ showVersion pandocTypesVersion
--
phony "decks" $ do
need ["support"]
need ["index"]
decksA >>= need
--
phony "html" $ do
need ["support"]
everythingA <++> indexA >>= need
need ["index"]
allHtmlA >>= need
--
phony "pdf" $
decksPdfA <++> pagesPdfA <++> handoutsPdfA <++> indexA >>= need
phony "pdf" $ do
need ["index"]
allPdfA >>= need
--
phony "pdf-decks" $ decksPdfA <++> indexA >>= need
phony "pdf-decks" $ do
need ["index"]
decksPdfA >>= need
--
phony "watch" $ do
need ["html"]
allMarkdownA <++> metaA <++> allImagesA >>= watchFiles
watchChangesAndRepeat
--
phony "open" $ do
need ["html"]
......@@ -94,11 +77,11 @@ main = do
--
phony "server" $ do
need ["watch"]
runHttpServer serverPort dirs Nothing
runHttpServer serverPort directories Nothing
--
phony "example" $ liftIO writeExampleProject
--
phony "index" $ need [index, "support"]
phony "index" $ need ["support", index]
--
priority 2 $
"//*-deck.html" %> \out -> do
......@@ -110,8 +93,8 @@ main = do
let src = replaceSuffix "-deck.pdf" "-deck.html" out
need [src]
putNormal $ src ++ " -> " ++ out
runHttpServer serverPort dirs Nothing
decktape [(serverUrl </> makeRelative publicDir src), out]
runHttpServer serverPort directories Nothing
decktape [serverUrl </> makeRelative (directories ^. public) src, out]
--
priority 2 $
"//*-handout.html" %> \out -> do
......@@ -142,28 +125,8 @@ main = do
else indexSource <.> "generated"
markdownToHtmlPage src out
--
indexSource <.> "generated" %> \out
-- deckSources <- deckSourcesA
-- pageSources <- pageSourcesA
-> do
decks <- decksA
decksPdf <- decksPdfA
pagesPdf <- pagesPdfA
handouts <- handoutsA
handoutsPdf <- handoutsPdfA
pages <- pagesA
-- let deckData =
-- transpose [deckSources, decks, handouts, decksPdf, handoutsPdf]
-- let pageData = transpose [pageSources, pages, pagesPdf]
need $ decks ++ handouts ++ pages
writeIndexLists
out
(takeDirectory index)
(zip decks decksPdf)
(zip handouts handoutsPdf)
(zip pages pagesPdf)
-- writeIndexTable out (takeDirectory index) deckData pageData
-- writeIndex out (takeDirectory index) decks handouts pages
indexSource <.> "generated" %> \out ->
writeIndexLists out (takeDirectory index)
--
priority 2 $
"//*.dot.svg" %> \out -> do
......@@ -195,66 +158,61 @@ main = do
sassc [src, out]
--
phony "clean" $ do
removeFilesAfter publicDir ["//"]
removeFilesAfter projectDir cruft
when isDevelopmentVersion $ removeFilesAfter appDataDir ["//"]
removeFilesAfter (directories ^. public) ["//"]
removeFilesAfter (directories ^. project) cruft
when isDevelopmentVersion $
removeFilesAfter (directories ^. appData) ["//"]
--
phony "help" $ do
text <- liftIO $ getResourceString "template/help-page.md"
liftIO $ putStr text
--
phony "plan" $ do
metaData <- readMetaDataForDir projectDir
putNormal $ "\nproject directory: " ++ projectDir
putNormal $ "public directory: " ++ publicDir
putNormal $ "support directory: " ++ supportDir
putNormal $ "application data directory: " ++ appDataDir
putNormal "\nmeta:\n"
metaA >>= mapM_ putNormal
putNormal "\nsources:\n"
allSourcesA >>= mapM_ putNormal
phony "info" $ do
putNormal $ "\nproject directory: " ++ (directories ^. project)
putNormal $ "public directory: " ++ (directories ^. public)
putNormal $ "support directory: " ++ (directories ^. support)
putNormal $ "application data directory: " ++ (directories ^. appData)
putNormal "\ntargets:\n"
everythingA <++> everythingPdfA >>= mapM_ putNormal
allHtmlA <++> allPdfA >>= mapM_ putNormal
putNormal "\ntop level meta data:\n"
putNormal $ groom metaData
groom <$> metaA >>= putNormal
--
phony "support" $ do
metaData <- readMetaDataForDir projectDir
unlessM (Development.Shake.doesDirectoryExist supportDir) $ do
liftIO $ createDirectoryIfMissing True publicDir
metaData <- metaA
unlessM (Development.Shake.doesDirectoryExist (directories ^. support)) $ do
liftIO $ createDirectoryIfMissing True (directories ^. public)
case metaValueAsString "provisioning" metaData of
Just value
| value == show SymLink ->
liftIO $ createFileLink (appDataDir </> "support") supportDir
liftIO $
createFileLink
((directories ^. appData) </> "support")
(directories ^. support)
Just value
| value == show Copy ->
liftIO $ copyDir (appDataDir </> "support") supportDir
liftIO $
copyDir
((directories ^. appData) </> "support")
(directories ^. support)
Nothing ->
liftIO $ createFileLink (appDataDir </> "support") supportDir
liftIO $
createFileLink
((directories ^. appData) </> "support")
(directories ^. support)
_ -> return ()
--
phony "check" checkExternalPrograms
--
phony "publish" $ do
need ["support"]
everythingA <++> indexA >>= need
metaData <- readMetaDataForDir projectDir
need ["index"]
allHtmlA <++> allPdfA >>= need
metaData <- metaA
let host = metaValueAsString "rsync-destination.host" metaData
let path = metaValueAsString "rsync-destination.path" metaData
if isJust host && isJust path
then do
let src = publicDir ++ "/"
let src = (directories ^. public) ++ "/"
let dst = intercalate ":" [fromJust host, fromJust path]
ssh [(fromJust host), "mkdir -p", (fromJust path)]
rsync [src, dst]
else throw RsyncUrlException
-- | Some constants that might need tweaking
options :: FilePath -> ShakeOptions
options projectDir =
shakeOptions
{ shakeFiles = ".shake"
, shakeColor = True
, shakeThreads = numCapabilities
, shakeAbbreviations = [(projectDir ++ "/", "")]
}
......@@ -18,4 +18,3 @@ main = do
forever $ do
getLine
reloadClients server
putStrLn "reload initiated!"
provisioning: Copy
exclude-directories:
- app
- bin
- code
- dist
- log
- node_modules
- public
- resource/support
- resource/template
- src
- src-support
executable := $(shell stack path | grep local-install-root | sed "s/local-install-root: //")/bin/decker
base-name := decker
executable := $(shell stack path | grep local-install-root | sed "s/local-install-root: //")/bin/decker
version := $(shell grep "version: " package.yaml | sed "s/version: *//")
branch := $(shell git branch | grep \* | cut -d ' ' -f2)
local-bin-path := $(HOME)/.local/bin
......@@ -10,19 +10,38 @@ else
decker-name := $(base-name)-$(version)-$(branch)
endif
resource-dir := $(HOME)/.local/share/$(decker-name)
ifdef DECKER_DEV
yarn-mode := development
else
yarn-mode := production
endif
JS_DEP_COPY = notes/notes.html
JS_DEP_COPY += notes/notes.js
JS_DEP_COPY += reveal.js-menu/menu.js
JS_DEP_COPY += reveal.js-menu/menu.css
JS_DEP_COPY += reveal.js-menu/font-awesome/css/all.css
JS_DEP_COPY += \
reveal.js-menu/font-awesome/webfonts/fa-solid-900.woff2 \
reveal.js-menu/font-awesome/webfonts/fa-regular-400.woff2 \
reveal.js-menu/font-awesome/webfonts/fa-solid-900.woff \
reveal.js-menu/font-awesome/webfonts/fa-regular-400.woff \
reveal.js-menu/font-awesome/webfonts/fa-solid-900.ttf \
reveal.js-menu/font-awesome/webfonts/fa-regular-400.ttf
JS_DEP_COPY += print/paper.css
JS_DEP_COPY += print/pdf.css
JS_DEP_COPY_FULL_PATH = $(addprefix resource/support/, $(JS_DEP_COPY))
less:
stack build -j 8 --fast 2>&1 | less
build:
stack build -j 8 --fast
yarn:
yarn: $(JS_DEP_COPY_FULL_PATH)
yarn install && yarn run webpack --mode $(yarn-mode)
cp -r node_modules/reveal.js-menu resource/support/
cp -r node_modules/reveal.js/plugin/notes resource/support/
dist: yarn build
rm -rf dist
......@@ -40,6 +59,14 @@ watch:
clean:
stack clean
rm -rf dist
rm -rf resource/support/*
build-profile:
stack build -j 8 --fast --work-dir .stack-work-profile --profile
profile: build-profile
stack exec -- decker clean
stack exec --work-dir .stack-work-profile -- decker +RTS -p
install: yarn build
stack exec -- decker clean
......@@ -47,7 +74,27 @@ install: yarn build
cp $(executable) "$(local-bin-path)/$(decker-name)"
ln -sf "$(decker-name)" $(local-bin-path)/$(base-name)
watch-resources:
find resource src-support -name "*.scss" -or -name "*.html" -or -name "*.js" | entr -pd make install-resources
install-resources: yarn
rsync -r resource/ $(resource-dir)
version:
@echo "$(decker-name)"
.PHONY: build clean test install dist docs yarn
##### Copy JS dependencies that can't be packed with webpack
resource/support/print/%: node_modules/reveal.js/css/print/%
mkdir -p $(@D) && cp $< $@
resource/support/notes/%: node_modules/reveal.js/plugin/notes/%
mkdir -p $(@D) && cp $< $@
resource/support/reveal.js-menu/%: node_modules/reveal.js-menu/%
mkdir -p $(@D) && cp $< $@
node_modules/%:
yarn install
......@@ -56,6 +56,9 @@ dependencies:
- highlighting-kate
- http-conduit
- http-types
- lens
- lens-aeson
- lens-action
- monad-loops
- mtl
- multimap
......@@ -63,6 +66,7 @@ dependencies:
- network-uri
- pandoc
- pandoc-citeproc
- pandoc-lens
- pandoc-types
- process
- pureMD5
......
provisioning: SymLink
\ No newline at end of file
......@@ -207,7 +207,7 @@ $$
# Blocks
## Block markup {.split}
## Block markup
- Level 2 headers start new block
- Blocks can be marked with attributes
......
......@@ -20,8 +20,14 @@ $endif$
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="$revealjs-url$/css/reveal.css">
<link rel="stylesheet" href="$decker-support-dir$/reveal.js-menu/font-awesome/css/all.css">
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? '$decker-support-dir$/print/pdf.css' : '$decker-support-dir$/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
$if(math)$
$math$
......@@ -50,7 +56,7 @@ $endif$
<!-- Decker's standard default CSS -->
<!--<link rel="stylesheet" href="$decker-support-dir$/decker.css">-->
<link rel="stylesheet" href="$decker-support-dir$/decker.css">
<!-- The last word on CSS for the power user -->
$for(css)$
......
<!DOCTYPE html>
<html$if(lang)$ lang="$lang$"$endif$$if(dir)$ dir="$dir$"$endif$>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
$for(author-meta)$
<meta name="author" content="$author-meta$">
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$">
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$">
$endif$
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
<style type="text/css">code{white-space: pre;}</style>
$if(quotes)$
<style type="text/css">q { quotes: "“" "”" "‘" "’"; }</style>
$endif$
$if(highlighting-css)$
<style type="text/css">
$highlighting-css$
</style>
$endif$
$for(css)$
<link rel="stylesheet" href="$css$">
$endfor$
<style type="text/css">
.container {
max-width:750px;
margin:0 auto;
}
.container .content {
min-height: 750px;
}
.page-header small {
white-space:nowrap;
}
.page-header h1 {
font-size: 180%;
}
h1 {
font-size: 150%;
}
h2 {
font-size: 130%;
}
h3 {
font-size: 110%;
}
.container p > img {
width: 100%;
}
.container h6.post-date {
margin-top: 5px;
margin-bottom: 5px;
}
.container h2.post-title {
margin-top: 10px;
}
.container address {
color: #888;
}
address p.date {
float: right;
}
.container img {
width: 75%;
margin: 0px auto;
}
.container video {
width: 75%;
margin: 0px auto;
}
</style>
$if(math)$
$math$
$endif$
<!--[if lt IE 9]>
<html$if(lang)$ lang="$lang$" $endif$$if(dir)$ dir="$dir$" $endif$>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> $for(author-meta)$
<meta name="author" content="$author-meta$"> $endfor$ $if(date-meta)$
<meta name="dcterms.date" content="$date-meta$"> $endif$ $if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$"> $endif$
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
<style type="text/css">
code {
white-space: pre;
}
</style>
$if(quotes)$
<style type="text/css">
q {
quotes: "“""”""‘""’";
}
</style>
$endif$
$if(highlighting-css)$
<style type="text/css">
$highlighting-css$
</style>
$endif$
<link rel="stylesheet" href="$decker-support-dir$/handout.css">
<script src="$decker-support-dir$/handout.js"></script>
<style type="text/css">
.container {
max-width: 750px;
margin: 0 auto;
}
.container .content {
min-height: 750px;
}
.page-header small {
white-space: nowrap;
}
.page-header h1 {
font-size: 1.8rem;
}
h1 {
font-size: 1.5rem;
}
h2 {
font-size: 1.3rem;
}
h3 {
font-size: 1.1rem;
}
h1 code {
font-size: 1.5rem;
}
h2 code {
font-size: 1.3rem;
}
h3 code {
font-size: 1.1rem;
}
code {
font-size: 1rem;
}
.container figure {
width: 100%;
padding-left: 3em;
padding-right: 3em;
}
.container figure>img {
width: 100%;
padding: 0px;
border: 1pt solid gray;
}
.container figure>video {
width: 100%;
padding: 0px;
border: 1pt solid gray;