Skip to content

Commit 17dcac8

Browse files
authored
Created watcher script to build site on changes. Updated Documentation. (#23)
* Added watch script * documenting scripts * Updating readme
1 parent ccca0d1 commit 17dcac8

File tree

6 files changed

+66
-25
lines changed

6 files changed

+66
-25
lines changed

README.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,42 @@
22

33
![CI](https://github.com/alxrsngrtn/pandoc-website-template/workflows/CI/badge.svg)
44

5-
TL;DR: A template to build static websites with [Pandoc](https://pandoc.org/), [Github Actions](http://github.com/actions) & [Github Pages](https://pages.github.com/).
5+
A template to build static websites with [Pandoc](https://pandoc.org/) & [Github Actions](http://github.com/actions).
66

77
## Use
88

9-
`bin/build` walks a source directory, invokes a Pandoc command for each target file, and copies assets to a destination folder.
9+
### `build`
10+
11+
`bin/build` walks the source directory, invokes Pandoc on each file, and copies assets to a destination folder.
1012

1113
This tool is configurable by environment variables.
1214

13-
| Variable | Description | Default |
14-
|-----------|-----------------------------------------------------|-------------------------------------------------------|
15-
| `SRC` | Root directory of input sources. | `src/` |
16-
| `DST` | Root directory for generated output. | `public/` |
17-
| `STATIC` | Directory for static assets. | `$SRC/static` |
18-
| `SRC_EXT` | Input sources file extension. | `md` |
19-
| `DST_EXT` | Output generation file extension. | `html` |
20-
| `HEADER` | path/to/header.html (`--include-before-body`). | `$SRC/header.html` |
21-
| `FOOTER` | path/to/footer.html (`--include-after-body`). | `$SRC/footer.html` |
22-
| `CSS` | path/to/style.css embedded in header of a web page. | `/main.css` |
15+
| Variable | Description | Default |
16+
|-----------|-----------------------------------------------------|--------------------|
17+
| `SRC` | Root directory of input sources. | `src/` |
18+
| `DST` | Root directory for generated output. | `public/` |
19+
| `STATIC` | Directory for static assets. | `$SRC/static` |
20+
| `SRC_EXT` | Input sources file extension. | `md` |
21+
| `DST_EXT` | Output generation file extension. | `html` |
22+
| `HEADER` | path/to/header.html (`--include-before-body`). | `$SRC/header.html` |
23+
| `FOOTER` | path/to/footer.html (`--include-after-body`). | `$SRC/footer.html` |
24+
| `CSS` | path/to/style.css embedded in header of a web page. | `/main.css` |
2325
| `PANOPTS` | Arguments to pass to Pandoc for each input file. | `--css $CSS --email-obfuscation=javascript --metadata-file=defaults.yml -f markdown_github+yaml_metadata_block -t html5 -B $HEADER -A $FOOTER` |
2426

2527
The defaults of this script are oriented for creating static websites. However, the configuration is general enough to
26-
support a wide variety of tasks; for instance, generating a CV or a slide deck.
28+
support a wide variety of tasks; for instance, generating a CV or a slide deck. See [these examples](https://pandoc.org/demos.html)
29+
for more inspiration.
30+
31+
32+
### `watch`
33+
34+
`bin/watch` will watch the source directory. On any changes, it will invoke the build script.
35+
36+
37+
### Deployment
38+
39+
This template will publish the static site to [Github Pages](https://pages.github.com) via [Github Actions](http://github.com/actions).
2740

28-
We use Github Actions and Github Pages to automatically update the website on source changes. Should this template
29-
be used beyond websites, the build script can be tuned setting CI environment variables.
3041

3142
## Thanks to
3243

bin/build

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#!/bin/sh
2+
#
3+
# Invoke pandoc on $SRC, copy $STATIC assets over to $DST.
4+
#
25

36
set -e
47

58
ROOT=$(dirname $0)/..
6-
SRC=${SRC:-"$ROOT/src"}
7-
DST=${DST:-"$ROOT/public"}
8-
STATIC=${STATIC:-"$SRC/static"}
9-
HEADER=${HEADER:-"$SRC/header.html"}
10-
FOOTER=${FOOTER:-"$SRC/footer.html"}
11-
CSS=${CSS:-"/main.css"}
12-
SRC_EXT=${SRC_EXT:-"md"}
13-
DST_EXT=${DST_EXT:-"html"}
14-
PANOPTS=${PANOPTS:-"--css $CSS --email-obfuscation=javascript --metadata-file=defaults.yml -f markdown_github+yaml_metadata_block -t html5 -B $HEADER -A $FOOTER"}
159

10+
. $ROOT/bin/env
1611
. $ROOT/bin/logging
1712

1813
mkdir -p $DST

bin/env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
#
3+
# Environment variables, with defaults.
4+
#
5+
ROOT=$(dirname "$0")/..
6+
SRC=${SRC:-"$ROOT/src"}
7+
DST=${DST:-"$ROOT/public"}
8+
STATIC=${STATIC:-"$SRC/static"}
9+
HEADER=${HEADER:-"$SRC/header.html"}
10+
FOOTER=${FOOTER:-"$SRC/footer.html"}
11+
CSS=${CSS:-"/main.css"}
12+
SRC_EXT=${SRC_EXT:-"md"}
13+
DST_EXT=${DST_EXT:-"html"}
14+
PANOPTS=${PANOPTS:-"--css $CSS --email-obfuscation=javascript --metadata-file=defaults.yml -f markdown_github+yaml_metadata_block -t html5 -B $HEADER -A $FOOTER"}

bin/install

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/sh
2+
#
3+
# Install pandoc on debian.
4+
#
25
curl -O -L -C - https://github.com/jgm/pandoc/releases/download/2.8/pandoc-2.8-1-amd64.deb
36
sudo dpkg -i pandoc-2.8-1-amd64.deb
47
rm pandoc-2.8-1-amd64.deb

bin/logging

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/sh
2+
#
3+
# Constants & functions for logging.
4+
#
25

36
RED="\033[91m"
4-
GRN="\033[92m"
57
MAG="\033[95m"
68
BLD="\033[1m"
79
END="\033[0m"

bin/watch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
#
3+
# Watch $SRC, re-build when any file changes.
4+
#
5+
6+
ROOT=$(dirname $0)/..
7+
. $ROOT/bin/env
8+
. $ROOT/bin/logging
9+
10+
if ! python3 -c "import whenchanged" > /dev/null 2>&1; then
11+
pip3 --disable-pip-version-check install when-changed
12+
fi
13+
14+
status "Watching, Ctrl+C to exit."
15+
16+
when-changed -r $SRC -c $ROOT/bin/build

0 commit comments

Comments
 (0)