Created
March 9, 2025 15:21
-
-
Save yadomi/15dfa269787640bed1de16282e509783 to your computer and use it in GitHub Desktop.
pandoc static site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -x | |
| PANDOC_BIN=./build-tools/bin/pandoc | |
| TMP_DIR=tmp | |
| STATIC_DIR=static | |
| OUTPUT_DIR=_site | |
| SOURCES=$(find posts/ -type f -name "*.md" | sort -r) | |
| BUILD_DATE=$( date +"%Y-%m-%d %H:%M" ) | |
| pre_build () { | |
| rm -rf $OUTPUT_DIR | |
| rm -rf $TMP_DIR | |
| mkdir -p $TMP_DIR | |
| mkdir -p $OUTPUT_DIR/posts | |
| } | |
| post_build () { | |
| cp -r $STATIC_DIR $OUTPUT_DIR/ | |
| rm -rf $TMP_DIR | |
| } | |
| build () { | |
| printf 'posts:\n' > $TMP_DIR/posts.yml | |
| for file in $SOURCES; do | |
| OUTPUT=$(echo $file | awk '{gsub(/\.md/, ".html"); print}') | |
| $PANDOC_BIN -s -t html5 --metadata-file=metadata.yml \ | |
| -V generatedAt="$BUILD_DATE" \ | |
| --template=./build-tools/template/post.html $file -o $OUTPUT_DIR/$OUTPUT | |
| $PANDOC_BIN -s -t plain --template=./build-tools/template/_posts.template.yml \ | |
| -V href=$OUTPUT $file \ | |
| -V generatedAt="$BUILD_DATE" >> $TMP_DIR/posts.yml | |
| done | |
| # Generate index.html | |
| $PANDOC_BIN -s -t html \ | |
| --metadata-file=metadata.yml \ | |
| --metadata-file=$TMP_DIR/posts.yml \ | |
| -V generatedAt="$BUILD_DATE" \ | |
| --template=./build-tools/template/index.html index.md -o $OUTPUT_DIR/index.html | |
| # Generate feed.xml | |
| $PANDOC_BIN -s -t plain \ | |
| --metadata-file=metadata.yml \ | |
| --metadata-file=$TMP_DIR/posts.yml \ | |
| -V generatedAt="$(date -d "$BUILD_DATE" -R)" \ | |
| --template=./build-tools/template/rss.xml index.md -o $OUTPUT_DIR/rss.xml | |
| } | |
| pre_build | |
| build | |
| post_build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| mkdir -p ./build-tools | |
| mkdir -p ./build-tools/template | |
| wget -P ./build-tools https://github.com/jgm/pandoc/releases/download/3.6.3/pandoc-3.6.3-linux-arm64.tar.gz | |
| tar -xzvf ./build-tools/pandoc-3.6.3-linux-arm64.tar.gz -C ./build-tools --strip-components=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment