Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building self-contained presentations and for passing extra variables to pandoc #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion example/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ with pkgs.lib;
src = ./.;
name = "example-presentation";
# reveal version can be changed with revealJS
# 3.5.0 is used by default
# 3.7.0 is used by default
revealVersion = "3.4.0";
extraPandocVariables = {
theme = "sky";
};
}
27 changes: 17 additions & 10 deletions mkPresentation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
pkgs
, src
, name
, revealVersion ? "3.5.0"
, revealVersion ? "3.7.0"
, selfContained ? false
# extra dependencies
,extraBuildInputs ? []
# assets to include in the result packages, typically examples
,assets ? []
, extraBuildInputs ? []
, extraPandocVariables ? {}
}:

with pkgs;
with pkgs.lib;

let
revealJS = fetchTarball "https://github.com/hakimel/reveal.js/archive/${revealVersion}.tar.gz";

extraVars = vars:
builtins.concatStringsSep "" (mapAttrsToList (name: value: "--variable " + name + "=" + value) vars);
in

pkgs.stdenv.mkDerivation rec {
stdenv.mkDerivation rec {
inherit name src;

preferLocalBuild = true;
allowSubstitutes = false;

# dependencies declaration
buildInputs = with pkgs; [ pandoc ] ++ extraBuildInputs;
buildInputs = [ pandoc ] ++ extraBuildInputs;

installPhase = ''
mkdir $out
for presentation in $(find . -name "*\.md"); do
id=$(basename $presentation ".md")
pandoc -t revealjs -s -o $out/"$id".html "$id".md
id="$(basename "$presentation" ".md")"
path="$(dirname "$presentation")"
mkdir -p "$out/$path"
pandoc --to=revealjs --variable revealjs-url=${revealJS} ${extraVars extraPandocVariables} --resource-path="$src/$path" --standalone ${optionalString selfContained "--self-contained"} --out="$out/$path/$id.html" "$presentation"
done
ln -s ${revealJS} $out/reveal.js
'';
}
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ example slides are in example/presentation.md.
Can be built by running:

```sh
$ nix-build example
$ nix-build --option build-use-sandbox false example
```

NOTE that `--option build-use-sandbox false` is required when using a
different theme than the default one and when `selfContained` is enabled
because Pandoc needs network access.