2024-04-13 20:06:56 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
2024-08-06 17:01:28 +00:00
|
|
|
rm -rf _site-tmp
|
|
|
|
mkdir -p _site-tmp
|
|
|
|
touch _site-tmp/index.md
|
2024-04-13 20:06:56 +00:00
|
|
|
buildDate="$(date '+%d %b %Y')"
|
|
|
|
|
|
|
|
# $1=file $2=add to index
|
|
|
|
convert_md_to_html() {
|
2024-08-06 17:01:28 +00:00
|
|
|
ls -la "$1"
|
2024-04-13 20:06:56 +00:00
|
|
|
fileName=$(basename "${1%.*}")
|
2024-04-13 22:25:02 +00:00
|
|
|
postDate=$(date '+%d %b %Y' -d "$(stat -c %y "$1" | awk '{print $1}')")
|
2024-04-13 20:06:56 +00:00
|
|
|
bodyClass="page"
|
|
|
|
|
|
|
|
if [ $2 -eq 1 ]; then
|
|
|
|
bodyClass="post"
|
2024-08-06 17:01:28 +00:00
|
|
|
echo "- [$(pandoc --template=pandoc-metadata.json "$1" | jq -r .title)](/$fileName.html) _${postDate}_" >> _site-tmp/index.md
|
2024-04-13 20:06:56 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-06 17:01:28 +00:00
|
|
|
pandoc --template=tpl-layout.html --highlight-style=zenburn --metadata buildDate="$buildDate" --metadata postDate="$postDate" --metadata bodyClass="$bodyClass" -f markdown -t html5 "$1" > _site-tmp/"$fileName".html
|
2024-04-13 20:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# posts
|
|
|
|
for post in _posts/*.md; do
|
|
|
|
convert_md_to_html "$post" 1
|
|
|
|
done
|
|
|
|
|
|
|
|
# drafts
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
for post in _drafts/*.md; do
|
|
|
|
convert_md_to_html "$post" 1
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# pages
|
|
|
|
for post in ./*.md; do
|
|
|
|
convert_md_to_html "$post" 0
|
|
|
|
done
|
|
|
|
|
|
|
|
# index
|
|
|
|
# is there a better way to invert the file?
|
2024-08-06 17:01:28 +00:00
|
|
|
echo "$(tac _site-tmp/index.md)" > _site-tmp/index.md
|
|
|
|
pandoc --template=tpl-layout.html --metadata isIndex=1 --metadata buildDate="$buildDate" --metadata bodyClass="index" -f markdown -t html5 _site-tmp/index.md > _site-tmp/index.html
|
2024-04-13 20:06:56 +00:00
|
|
|
|
|
|
|
# static files
|
2024-08-06 17:01:28 +00:00
|
|
|
cp -r static _site-tmp/static
|
|
|
|
cp -r assets _site-tmp/assets
|
|
|
|
cp -r root/* _site-tmp/
|
2024-04-13 20:06:56 +00:00
|
|
|
# concat css
|
2024-08-06 17:01:28 +00:00
|
|
|
cat static/reset.css static/styles.css > _site-tmp/static/css.css
|
|
|
|
|
|
|
|
rm -rf _site
|
|
|
|
mv _site-tmp _site
|