Преглед на файлове

Engine bug fixes and cleanup

webp
Yann Esposito (Yogsototh) преди 2 месеца
родител
ревизия
2bffa4154b
Подписан от: yogsototh GPG ключ ID: 7B19A4C650D59646
  1. 27
      Makefile
  2. 3
      engine/compresscss.sh
  3. 69
      engine/optim-classes.sh
  4. 26
      engine/optim-html.sh

27
Makefile

@ -1,6 +1,5 @@
# Generate my website out of org-mode/gemini files
all: site
SRC_DIR ?= src
DST_DIR ?= _site
@ -11,10 +10,20 @@ NO_DRAFT := -not -path '$(SRC_DIR)/drafts/*'
# we don't copy source files
NO_SRC_FILE := ! -name '*.org'
# Prevent path/nix bugs
ENV_VARS := ./engine/envvars.sh
NIX_FILES := ./shell.nix $(shell find nix -type f)
$(ENV_VARS): $(NIX_FILES)
$(info Build ${ENV_VARS})
@echo "export PATH=\"${PATH}\"" >> ./engine/envvars.sh
.PHONY: envvars
envvars: $(ENV_VARS)
ALL += envvars
# ASSETS
SRC_RAW_FILES := $(shell find $(SRC_DIR) -type f $(NO_DRAFT) $(NO_SRC_FILE))
DST_RAW_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
$(DST_DIR)/%: $(SRC_DIR)/%
$(DST_DIR)/%: $(SRC_DIR)/% $(ENV_VARS)
@mkdir -p "$(dir $@)"
cp "$<" "$@"
.PHONY: assets
@ -24,7 +33,7 @@ ALL += assets
# CSS
SRC_CSS_FILES := $(shell find $(SRC_DIR) -type f -name '*.css')
DST_CSS_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
$(DST_DIR)/%.css: $(SRC_DIR)/%.css
$(DST_DIR)/%.css: $(SRC_DIR)/%.css $(ENV_VARS)
@mkdir -p "$(dir $@)"
minify "$<" > "$@"
css: $(DST_CSS_FILES)
@ -40,7 +49,7 @@ PANDOC_TEMPLATE ?= templates/post.html
PANDOC_LUA_FILTER ?= engine/links-to-html.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)
$(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(MK_HTML) $(ENV_VARS)
@mkdir -p "$(dir $@)"
$(PANDOC) "$<" "$@.tmp"
minify --mime text/html "$@.tmp" > "$@"
@ -57,7 +66,7 @@ RSS_CACHE_DIR ?= $(CACHE_DIR)/rss
DST_XML_FILES ?= $(patsubst %.org,%.xml, \
$(patsubst $(SRC_POSTS_DIR)/%,$(RSS_CACHE_DIR)/%, \
$(SRC_POSTS_FILES)))
$(RSS_CACHE_DIR)/%.xml: $(DST_POSTS_DIR)/%.html
$(RSS_CACHE_DIR)/%.xml: $(DST_POSTS_DIR)/%.html $(ENV_VARS)
@mkdir -p "$(dir $@)"
hxclean "$<" > "$@"
.PHONY: indexcache
@ -75,19 +84,13 @@ $(INDEX_CACHE_DIR)/%.index: $(INDEX_CACHE_DIR)/%.xml $(MK_INDEX_ENTRY) $(ENV_VAR
HTML_INDEX := $(DST_DIR)/index.html
MKINDEX := engine/mk-index.sh
INDEX_TEMPLATE ?= templates/index.html
$(HTML_INDEX): $(DST_INDEX_FILES) $(MKINDEX) $(INDEX_TEMPLATE)
$(HTML_INDEX): $(DST_INDEX_FILES) $(MKINDEX) $(INDEX_TEMPLATE) $(ENV_VARS)
@mkdir -p $(DST_DIR)
$(MKINDEX)
.PHONY: index
index: $(HTML_INDEX)
ALL += index
ENV_VARS := ./engine/envvars.sh
NIX_FILES := ./shell.nix $(shell find nix -type f)
$(ENV_VARS): $(NIX_FILES)
@echo "export PATH=\"${PATH}\"" >> ./engine/envvars.sh
ALL += ./engine/envvars.sh
# RSS
DST_RSS_FILES ?= $(patsubst %.xml,%.rss, $(DST_XML_FILES)) $(ENV_VARS)
MK_RSS_ENTRY := ./engine/mk-rss-entry.sh

3
engine/compresscss.sh

@ -1,3 +0,0 @@
#!/usr/bin/env bash
minify "$1" > "$2"

69
engine/optim-classes.sh

@ -1,69 +0,0 @@
#!/usr/bin/env zsh
cd "$(git rev-parse --show-toplevel)" || exit 1
webdir="_optim"
retrieve_classes_in_html () {
cat $webdir/**/*.html | \
perl -pe 's/class="?([a-zA-Z0-9_-]*)/\nCLASS: $1\n/g'
}
retrieve_classes_in_css () {
cat $webdir/**/*.css | \
perl -pe 's/ \.([a-zA-Z-_][a-zA-Z0-9-_]*)/\nCLASS:$1\n/g'
}
classes=( $( {retrieve_classes_in_html; retrieve_classes_in_css}| \
egrep "^CLASS: [^ ]*$" |\
sort -u | \
awk '$2 !~ /(gzwebfilesize|webfilesize|yyydate|example|src)/ {print length($2),$2}'|\
sort -rn | \
awk '{print $2}') )
chr() {
[ "$1" -lt 26 ] || return 1
printf "\\$(printf '%03o' $(( 97 + $1 )))"
}
shortName() {
if [ "$1" -gt 25 ]; then
print -- $(shortName $(( ( $1 / 26 ) - 1 )))$(shortName $(( $1 % 26 )))
else
chr $1
fi
}
i=0;
typeset -A assoc
for c in $classes; do
sn=$(shortName $i)
print -- "$c -> $sn"
assoc[$c]=$sn
((i++))
done
htmlreplacer=''
cssreplacer=''
for long in $classes; do
htmlreplacer=$htmlreplacer's#class=("?)'${long}'#class=$1'${assoc[$long]}'#g;'
cssreplacer=$cssreplacer's#\.'${long}'#.'${assoc[$long]}'#g;'
done
sizeof() {
stat --format="%s" "$*"
}
for fic in $webdir/**/*.{html,xml}(N); do
before=$(sizeof $fic)
print -n -- "$fic ($before"
perl -pi -e $htmlreplacer $fic
after=$(sizeof $fic)
print -- " => $after [$(( ((before - after) * 100) / before ))%])"
done
for fic in $webdir/**/*.css(N); do
before=$(sizeof $fic)
print -n -- "$fic ($before"
perl -pi -e $cssreplacer $fic
after=$(sizeof $fic)
print -- " => $after [$(( ((before - after) * 100) / before ))%])"
done

26
engine/optim-html.sh

@ -1,26 +0,0 @@
#!/usr/bin/env zsh
cd "$(git rev-parse --show-toplevel)" || exit 1
webdir="_optim"
debug () {
print -- $* >/dev/null
}
type -a filelist
setopt extendedglob
if (($#>0)); then
filelist=( $* )
else
filelist=( $webdir/**/*.html(.) )
fi
tmp=$(mktemp)
for fic in $filelist; do
print -n -- "$fic "
cp $fic $tmp
perl -pi -e 's#<div id="outline-container-[^"]*"([^>]*)>#<div$1>#g;s# id="org[a-f0-9]{7}"##g;s# class="src src-# class="src-#g;s#<label class="org-src-name">#<label>#g;s#<div class="org-src-container">#<div>#g' $tmp
minify --mime text/html $tmp > $fic
print "[OK]"
done
Зареждане…
Отказ
Запис