todo: fix gif
This commit is contained in:
Yann Esposito (Yogsototh) 2021-09-30 00:43:40 +02:00
parent 2bffa4154b
commit d937afc208
Signed by untrusted user who does not match committer: yogsototh
GPG Key ID: 7B19A4C650D59646
5 changed files with 27 additions and 6 deletions

View File

@ -47,9 +47,10 @@ DST_PANDOC_FILES ?= $(patsubst %$(EXT),%.html, \
$(SRC_PANDOC_FILES)))
PANDOC_TEMPLATE ?= templates/post.html
PANDOC_LUA_FILTER ?= engine/links-to-html.lua
PANDOC_LUA_FILTER_IMG ?= engine/img-to-webp.lua
MK_HTML := engine/mk-html.sh
PANDOC := $(MK_HTML) $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER)
$(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(MK_HTML) $(ENV_VARS)
PANDOC := $(MK_HTML) $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG)
$(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG) $(MK_HTML) $(ENV_VARS)
@mkdir -p "$(dir $@)"
$(PANDOC) "$<" "$@.tmp"
minify --mime text/html "$@.tmp" > "$@"

9
engine/img-to-webp.lua Normal file
View File

@ -0,0 +1,9 @@
-- img-to-webp.lua
function Image(el)
local fileext = el.src:match("%.[^%.]+$");
-- DEBUG -- print("LUA IMG: ", fileext);
if ( fileext == ".jpg" or fileext == ".png" or fileext == ".jpeg" ) then
el.src = el.src .. ".webp"
end
return el
end

View File

@ -4,8 +4,9 @@ set -eu
cd "$(git rev-parse --show-toplevel)" || exit 1
template="$1"
luafilter="$2"
orgfile="$3"
htmlfile="$4"
luafilterimg="$3"
orgfile="$4"
htmlfile="$5"
tocoption=""
if grep -ie '^#+options:' "$orgfile" | grep 'toc:t'>/dev/null; then
@ -16,6 +17,7 @@ set -x
pandoc $tocoption \
--template="$template" \
--lua-filter="$luafilter" \
--lua-filter="$luafilterimg" \
--mathml \
--from org \
--to html5 \

View File

@ -7,10 +7,18 @@ sizeof() {
stat --format="%s" "$*"
}
convert "$src" -resize 800x800\> -quality 50 "$dst"
convert "$src" -resize 800x800\> "$dst"
before=$(sizeof $src)
after=$(sizeof $dst)
if [[ "${src:e}" == "gif" ]]; then
after=$(sizeof $dst)
else
cwebp "$dst" -quiet -o "$dst.webp"
after=$(sizeof $dst.webp)
fi
if (( before <= after )); then
cp -f "$src" "$dst"

View File

@ -24,6 +24,7 @@ pkgs.mkShell {
direnv
ghc
tmux
libwebp
# for emacs dev
ripgrep
nodePackages.http-server