diff --git a/content/posts/smart-rice-cooker/media/connections.svg b/content/posts/smart-rice-cooker/media/connections.svg
new file mode 100644
index 0000000..6a6ed6e
--- /dev/null
+++ b/content/posts/smart-rice-cooker/media/connections.svg
@@ -0,0 +1,353 @@
+
+
+
+
+
diff --git a/content/posts/smart-rice-cooker/media/src/.env b/content/posts/smart-rice-cooker/media/src/.env
new file mode 100644
index 0000000..e69de29
diff --git a/content/posts/smart-rice-cooker/media/src/rice_build.sh b/content/posts/smart-rice-cooker/media/src/rice_build.sh
new file mode 100755
index 0000000..ea540d0
--- /dev/null
+++ b/content/posts/smart-rice-cooker/media/src/rice_build.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+if [ "${1}" == '-d' ]; then
+ echo 'src/rice_connections.dot'
+ exit
+fi
+
+__target='connections.svg'
+
+if [ "${1}" == '-t' ]; then
+ echo "${__target}"
+ exit
+fi
+
+sed -e 's/\[depend_value\]/[color=blue]/' \
+ -e 's/\[proxy_value\]/\[color=deepskyblue\]/' \
+ -e 's/\[proxy_function\]/\[color=dodgerblue\]/' \
+ -e 's/\[documented\]/\[fillcolor=darkolivegreen1\]/' \
+ -e 's/\[done\]/\[fillcolor=chartreuse\]/' \
+ -e 's/\[depend_function\]/\[color=cornflowerblue\]/' 'src/rice_connections.dot' | fdp -Ln5 -Tsvg >"${__target}"
+
+exit
diff --git a/content/posts/smart-rice-cooker/media/src/rice_build.sh.hash b/content/posts/smart-rice-cooker/media/src/rice_build.sh.hash
new file mode 100644
index 0000000..fa3428a
--- /dev/null
+++ b/content/posts/smart-rice-cooker/media/src/rice_build.sh.hash
@@ -0,0 +1 @@
+8c980661e6c1b89a78f54e068a10dd93
diff --git a/src/rice_connections.dot b/content/posts/smart-rice-cooker/media/src/rice_connections.dot
similarity index 99%
rename from src/rice_connections.dot
rename to content/posts/smart-rice-cooker/media/src/rice_connections.dot
index a2743e7..d7846d6 100644
--- a/src/rice_connections.dot
+++ b/content/posts/smart-rice-cooker/media/src/rice_connections.dot
@@ -176,5 +176,4 @@ digraph {
////////////////////////////////////////////////////////////////////////////////
-
}
diff --git a/src/images_build.sh b/src/images_build.sh
index 377cf30..dcd1c9c 100755
--- a/src/images_build.sh
+++ b/src/images_build.sh
@@ -50,18 +50,22 @@ __PROCESS_PNG=true
__depends__PROCESS_PNG=(PNG_OPTIMIZE PNG_RESCALE)
__PNG_OPTIMIZE=false
__depends__PNG_OPTIMIZE=(PNG_EFFORT)
-__PNG_EFFORT=9
+# quick/default/more/placebo
+__PNG_EFFORT='quick'
__PNG_RESCALE=true
-__depends__PNG_RESCALE=(PNG_SCALE)
+__depends__PNG_RESCALE=(PNG_SCALE PNG_QUALITY)
__PNG_SCALE="${__global_scale}"
+__PNG_QUALITY=0
-__ENVIRONMENT_LIST='JPEG_QUALITY
+__ENVIRONMENT_LIST='PROCESS_JPEG
+PROCESS_PNG
+PROCESS_SCRIPT
+JPEG_QUALITY
JPEG_RESCALE
JPEG_SCALE
JPEG_OPTIMIZE
-PROCESS_JPEG
-PROCESS_PNG
PNG_OPTIMIZE
+PNG_QUALITY
PNG_EFFORT
PNG_RESCALE
PNG_SCALE'
@@ -70,11 +74,11 @@ PNG_SCALE'
# Functions
###############################################################################
-__fatal_error_handler(){
-if [ "${__fatal_error}" == 'true' ]; then
- echo 'Fatal Error: Exiting'
- exit
-fi
+__fatal_error_handler() {
+ if [ "${__fatal_error}" == 'true' ]; then
+ echo 'Fatal Error: Exiting'
+ exit
+ fi
}
########################################
@@ -212,6 +216,17 @@ __clear_env() {
}
+__unset_unused() {
+ while read -r __var; do
+ #local "${__var}"
+ if [ "${__var}" != "__PROCESS_${1^^}" ]; then
+ eval "${__var#__}"='false'
+ fi
+ done < <(set | grep -E '^__PROCESS_' | sed 's/^\([^=]*\)=.*/\1/')
+
+ __resolve_env
+}
+
########################################
# __process <.env>
########################################
@@ -224,6 +239,8 @@ __clear_env() {
__process() {
+ __process_scripts
+
if [ "${PROCESS_JPEG}" == 'true' ]; then
__process_generic_image jpeg
fi
@@ -244,14 +261,7 @@ __find_png() {
__process_generic_image() {
- while read -r __var; do
- #local "${__var}"
- if [ "${__var}" != "__PROCESS_${1^^}" ]; then
- eval "${__var#__}"='false'
- fi
- done < <(set | grep -E '^__PROCESS_' | sed 's/^\([^=]*\)=.*/\1/')
-
- __resolve_env
+ __unset_unused "${1}"
"__find_${1}" | while read -r __source_file; do
@@ -305,6 +315,69 @@ __optimize_jpeg() {
jpegoptim -s "${1}" 1>/dev/null
}
+__rescale_png() {
+ convert "${1}" -quality "${PNG_QUALITY}" -auto-orient -resize "${PNG_SCALE}"% "${2}"
+}
+
+__optimize_png() {
+
+ local __options=''
+
+ case $variable-name in
+ 'quick')
+ __options='-q'
+ ;;
+ 'default')
+ __options=''
+ ;;
+ 'more')
+ __options='-m'
+ ;;
+ 'placebo')
+ __options='--iterations=500 --filters=01234mepb --lossy_8bit --lossy_transparent'
+ ;;
+ *)
+ echo "Unknown PNG_EFFORT option '${PNG_EFFORT}', defaulting to 'quick'"
+ __options='-q'
+ ;;
+ esac
+
+ zopflipng -y ${__options} "${1}" "${1}"
+}
+
+__process_scripts() {
+
+ __unset_unused SCRIPT
+
+ find './src/' -type f \( -iname \*.sh \) | while read -r __source_file; do
+
+ export FILE_HASH="$(
+ {
+ md5sum "${__source_file}"
+ "${__source_file}" -d | sort | while read -r __file; do
+ md5sum "${__file}"
+ done
+ } | sort | md5sum -
+ )"
+
+ if ! __check_file "${__source_file}" "$("${__source_file}" -t)"; then
+
+ echo "Running: ${__source_file}"
+
+ echo "$(__hash_env)" >"$(__get_hash_file "${__source_file}")"
+
+ "${__source_file}"
+
+ fi
+
+ unset FILE_HASH
+
+ done
+
+ __set_env './src/.env'
+
+}
+
########################################
# __get_hash_file
########################################
@@ -319,7 +392,7 @@ __get_hash_file() {
}
########################################
-# __check_file
+# __check_file [ ...]
########################################
#
# Check File
@@ -331,12 +404,35 @@ __check_file() {
__hash_file="$(__get_hash_file "${1}")"
- __target="$(sed 's|^\./src/|./|' <<<"${1}")"
+ shift
+
+ __targets=''
+
+ if [ "${#}" == '0' ]; then
+
+ __targets="$(sed 's|^\./src/|./|' <<<"${1}")"
+
+ else
+
+ until [ "${#}" == '0' ]; do
+
+ __targets="${__target}
+${1}"
+
+ shift
+
+ done
- if ! [ -e "${__target}" ]; then
- return 1
fi
+ while read -r __target; do
+
+ if ! [ -e "${__target}" ]; then
+ return 1
+ fi
+
+ done
+
if [ -e "${__hash_file}" ]; then
__file_hash="$(cat "${__hash_file}")"
if [ "${__file_hash}" == "$(__hash_env)" ]; then
diff --git a/src/rice_build.sh b/src/rice_build.sh
deleted file mode 100755
index 240738e..0000000
--- a/src/rice_build.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-
-__target='./static/images/generated/rice/connections.svg'
-
-mkdir -p "$(dirname "${__target}")"
-
-sed -e 's/\[depend_value\]/[color=blue]/' \
--e 's/\[proxy_value\]/\[color=deepskyblue\]/' \
--e 's/\[proxy_function\]/\[color=dodgerblue\]/' \
--e 's/\[documented\]/\[fillcolor=darkolivegreen1\]/' \
--e 's/\[done\]/\[fillcolor=chartreuse\]/' \
--e 's/\[depend_function\]/\[color=cornflowerblue\]/' 'src/rice_connections.dot' | fdp -Ln5 -Tsvg > "${__target}"
-
-exit