Skip to content

Commit 35a8dc8

Browse files
authored
Initial commit
0 parents  commit 35a8dc8

27 files changed

Lines changed: 543 additions & 0 deletions

.github/workflows/build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: pandoc-build
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
build-and-test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
persist-credentials: false
15+
16+
- name: Cache Pandoc Package
17+
uses: actions/cache@v3
18+
with:
19+
path: pandoc.deb
20+
key: pandoc-deb-3.6.3
21+
restore-keys: |
22+
pandoc-deb-
23+
24+
- name: Cache Pandoc RSS
25+
uses: actions/cache@v3
26+
with:
27+
path: rss
28+
key: pandoc-rss-${{ hashFiles('**/install') }}
29+
restore-keys: |
30+
pandoc-rss-
31+
32+
- name: Install Pandoc
33+
run: bin/install
34+
35+
- name: Build Website
36+
run: bin/build
37+

.github/workflows/pages.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#
2+
# Deploy is based on this example:
3+
# https://github.com/actions/starter-workflows/blob/main/pages/hugo.yml
4+
#
5+
name: pages-deploy
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
21+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
22+
concurrency:
23+
group: "pages"
24+
cancel-in-progress: false
25+
26+
jobs:
27+
build:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v2
31+
with:
32+
persist-credentials: false
33+
34+
- name: Cache Pandoc Package
35+
uses: actions/cache@v3
36+
with:
37+
path: pandoc.deb
38+
key: pandoc-deb-3.6.3
39+
restore-keys: |
40+
pandoc-deb-
41+
42+
- name: Cache Pandoc RSS
43+
uses: actions/cache@v3
44+
with:
45+
path: rss
46+
key: pandoc-rss-${{ hashFiles('**/install') }}
47+
restore-keys: |
48+
pandoc-rss-
49+
50+
- name: Install Pandoc
51+
run: bin/install
52+
53+
- name: Build Website
54+
run: bin/build
55+
56+
- name: Upload artifact
57+
uses: actions/upload-pages-artifact@v3
58+
with:
59+
path: ./public
60+
61+
deploy:
62+
runs-on: ubuntu-latest
63+
needs: build
64+
environment:
65+
name: github-pages
66+
url: ${{ steps.deployment.outputs.page_url }}
67+
68+
steps:
69+
- name: Deploy to GitHub Pages
70+
id: deployment
71+
uses: actions/deploy-pages@v4

.github/workflows/shellcheck.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: shellcheck
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
persist-credentials: false
17+
18+
- name: Run ShellCheck
19+
uses: ludeeus/action-shellcheck@master
20+
env:
21+
SHELLCHECK_OPTS: -x

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public/
2+
.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-2020 Alex Merose
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Pandoc Website Template
2+
3+
[![pages-deploy](https://github.com/alxmrs/pandoc-website-template/actions/workflows/pages.yml/badge.svg)](https://github.com/alxmrs/pandoc-website-template/actions/workflows/pages.yml)
4+
[![shellcheck](https://github.com/alxmrs/pandoc-website-template/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/alxmrs/pandoc-website-template/actions/workflows/shellcheck.yml)
5+
6+
A template to build static websites with [Pandoc](https://pandoc.org/).
7+
8+
Demo site: [pandoc.merose.com](https://pandoc.merose.com/).
9+
10+
## Use
11+
12+
### `build`
13+
14+
`bin/build` walks the source directory, invokes Pandoc on each file, and copies assets to a destination folder. It also
15+
gathers all files not named "index.md" into an RSS feed.
16+
17+
This tool is configurable by environment variables.
18+
19+
| Variable | Description | Default |
20+
|-----------|-----------------------------------------------------|--------------------------------------------------------------------------------------|
21+
| `SRC` | Root directory of input sources. | `src/` |
22+
| `DST` | Root directory for generated output. | `public/` |
23+
| `ASSETS` | Directory for static assets, like CSS and images | `assets/` |
24+
| `SRC_EXT` | Input sources file extension. | `md` |
25+
| `DST_EXT` | Output generation file extension. | `html` |
26+
| `HEADER` | path/to/header.html (`--include-before-body`). | `template/header.html` |
27+
| `FOOTER` | path/to/footer.html (`--include-after-body`). | `template/footer.html` |
28+
| `CSS` | path/to/style.css embedded in header of a web page. | `/assets/css/main.css` |
29+
| `PANOPTS` | Arguments to pass to Pandoc for each input file. | `--css $CSS --metadata-file=$ROOT/defaults.yml -B $HEADER -A $FOOTER" -V lang=en-US` |
30+
31+
To make it easier to edit metadata for every page, consider making changes to the `defaults.yml` at the project root.
32+
33+
> Note: Configuring RSS still needs to happen in the `bin/build` file today.
34+
35+
The defaults of this script are oriented for creating static websites. However, the configuration could be molded to
36+
support a wide variety of tasks; for instance, generating a CV or a slide deck. See [these examples](https://pandoc.org/demos.html)
37+
for more inspiration.
38+
39+
40+
### `watch`
41+
42+
`bin/watch` will watch the source directory. On any changes, it will invoke the build script.
43+
44+
> Note: if you change files outside of `$SRC` (i.e. in `template/` or `assets/`), you'll need to terminate and
45+
> re-run this script.
46+
47+
### Deployment
48+
49+
This template will publish the static site to [Github Pages](https://pages.github.com) via [Github Actions](http://github.com/actions).
50+
51+
52+
## Thanks to
53+
54+
- The [contributors of Pandoc](https://github.com/jgm/pandoc/graphs/contributors)
55+
- Will Styler's [inspiration](http://wstyler.ucsd.edu/posts/lmimg/spcv.txt)
56+
- [Pure sh Bible](https://github.com/dylanaraps/pure-sh-bible)
57+
- [Drew McConville](http://bettermotherfuckingwebsite.com/)

assets/Pandoc-Web-Preview.png

146 KB
Loading

assets/birth-aging-dying.webp

669 KB
Loading

assets/css/main.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* thanks https://bettermotherfuckingwebsite.com */
2+
body {
3+
margin: 40px auto;
4+
max-width: 650px;
5+
line-height: 1.6;
6+
font-size: 18px;
7+
color: #444;
8+
padding: 0 10px
9+
}
10+
11+
h1, h2, h3 {
12+
line-height: 1.2
13+
}
14+
15+
nav ul {
16+
padding: 0;
17+
list-style: none;
18+
font-weight: bold;
19+
}
20+
21+
nav ul li {
22+
display: inline;
23+
margin-right: 20px;
24+
line-height: 2.5em;
25+
}
26+
27+
img {
28+
max-width: 95%;
29+
}
30+
31+
/*Thanks https://css-tricks.com/snippets/css/simple-and-nice-blockquote-styling */
32+
blockquote {
33+
filter: opacity(75%);
34+
border-left: 10px solid #ccc;
35+
margin: 1.5em 10px;
36+
padding: 0.5em 10px;
37+
quotes: "\201C""\201D""\2018""\2019";
38+
}
39+
blockquote:before {
40+
content: open-quote;
41+
font-size: 4em;
42+
line-height: 0.1em;
43+
margin-right: 0.25em;
44+
vertical-align: -0.4em;
45+
}
46+
blockquote p {
47+
display: inline;
48+
}

bin/build

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Invoke pandoc on $SRC, copy $ASSETS assets over to $DST.
4+
# Also, generates an RSS feed from non-index.md files.
5+
#
6+
7+
set -e
8+
9+
ROOT=$(dirname "$(dirname "$0")")
10+
# shellcheck source=bin/env
11+
. "$ROOT"/bin/env
12+
# shellcheck source=bin/logging
13+
. "$ROOT"/bin/logging
14+
15+
mkdir -p "$DST"
16+
17+
convert() {
18+
file="$1"
19+
# Strip `src` path from file string
20+
FROM="${file##"$SRC"}"
21+
22+
# Apply the mappings as follows:
23+
# src/some/path/webpage.md --> public/some/path/webpage/index.html
24+
# src/some/path/index.md --> public/some/path/index.html
25+
# In other words: Let the file name become the slug name
26+
# and let any index page simply become an index.hml page.
27+
filename=$(basename "$FROM")
28+
if echo "$filename" | grep -q 'index\.md$'; then
29+
TO="${FROM%%"$SRC_EXT"}$DST_EXT"
30+
else
31+
TO="${FROM%%".$SRC_EXT"}/index.$DST_EXT"
32+
fi
33+
# Define a target file with the new extension
34+
echo "$FROM --> $TO"
35+
mkdir -p "$(dirname "$DST$TO")"
36+
# shellcheck disable=SC2086
37+
pandoc $PANOPTS "$file" --output="$DST$TO" || warn "Failed to create $TO"
38+
}
39+
40+
status "Rendering"
41+
find "$SRC" -type f -name "*.$SRC_EXT" | while IFS= read -r file; do
42+
convert "$file" &
43+
done
44+
wait
45+
46+
status "Copying over assets"
47+
cp -r "$ASSETS" "$DST"
48+
# Copies all non-source files to the destination, mirroring file structure.
49+
(cd "$SRC" && find . -type f -not -name "*.$SRC_EXT" -print | cpio -pdm "$DST")
50+
51+
status "Rendering RSS feed"
52+
# This does the following:
53+
# 1. Get all the markdown files in $SRC that are not an index
54+
# 2. Parse the "date" field from the YAML section, sort the files by date
55+
# 3. Print out only the paths to the files.
56+
ORDERED_POSTS=$({
57+
find "$SRC" -type f -name "*.md" | grep -v "index.md$" \
58+
| xargs grep "date:" | awk -F ": " '{print $1 " " $2}' | sort -k 2r \
59+
| awk -F ":" '{print $1}'
60+
})
61+
echo "$ORDERED_POSTS"
62+
# shellcheck disable=SC2086
63+
pandoc-rss -s \
64+
-t "My Pandoc Blog" \
65+
-d "A blog built with Pandoc" \
66+
-l "https://pandoc.merose.com" \
67+
-f "%s/" \
68+
-c "MIT or CC BY-SA 4.0" \
69+
-w "you@example.com (Kilgore Trout)" \
70+
-n "en-US" \
71+
$ORDERED_POSTS > "$DST/rss.xml"

0 commit comments

Comments
 (0)