From 3fd004b08d6303ba5a445ab9007762c10fde7c6b Mon Sep 17 00:00:00 2001 From: Bradley Sepos Date: Thu, 25 Jan 2018 04:52:16 -0500 Subject: [PATCH] build: Update to marsh 0.6.0. Adds support for images with multiple resolution assets. Implemented using the srcset attribute. Given an image foo.png, simply add foo@2x.png and/or foo@3x.png next to the standard resolution asset, and marsh will do the rest. --- marsh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/marsh b/marsh index c0d69fa3..925a2871 100755 --- a/marsh +++ b/marsh @@ -1,12 +1,12 @@ #!/bin/bash # marsh - build static websites using markdown and bash # -# Copyright 2017 Bradley Sepos +# Copyright 2018 Bradley Sepos # Released under the MIT License. See LICENSE for details. # https://github.com/bradleysepos/marsh NAME="marsh" -VERSION="0.5.0" +VERSION="0.6.0" SELF="${BASH_SOURCE[0]}" SELF_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd -P) SELF_DIR="${SELF_DIR:-$(pwd)}" @@ -1750,10 +1750,22 @@ function build_document { # build_document dest_dir target_dir document advance if [[ "${DOCUMENT_EXT}" == "markdown" ]]; then # preprocess markdown to add implicit figures # convert preprocessed markdown to html + # unwrap figures (remove p tag) + # process images with multiple resolution assets cp "${DOCUMENT}.${MARSH_UID}.document" "${DOCUMENT}.${MARSH_UID}.document.temp" <"${DOCUMENT}.${MARSH_UID}.document.temp" sed -E \ - -e 's|^!\[(.+)]\([ ]*([^ ]+)[ ]*"(.+)"[ ]*\)$|
\1
\3
|' | - process_markdown > "${DOCUMENT}.${MARSH_UID}.document" + -e 's|^!\[(.+)]\([ ]*([^ ]+)[ ]*"(.+)"[ ]*\)$|
\1
\3
|' | + process_markdown | + sed -E \ + -e 's|

|
|' \ + -e 's|

|
|' | + awk -F' ' 'BEGIN { ORS=" "; } { for(i=1; i<=NF; i++) { if ($i ~ "^src=\"[^\"]+\"$") { f=$i; gsub(/^src="/, "", f); gsub(/"$/, "", f); f1=f " 1x"; f2=f; gsub(/\.[^\.]+$/, "@2x&", f2); f2abs="'${DEST_DIR}/${TARGET_DIR}/${DOCUMENT_DIR}/'" f2; f3=f; gsub(/\.[^\.]+$/, "@3x&", f3); f3abs="'${DEST_DIR}/${TARGET_DIR}/${DOCUMENT_DIR}/'" f3; if (getline temp < f2abs > 0) { f2=", " f2 " 2x"; } else { f2=""; } if (getline temp < f3abs > 0) { f3=", " f3 " 3x"; } else { f3=""; } print "src=\"" f "\" srcset=\"" f1 f2 f3 "\" " } else { print $i } } }' | + sed -E \ + -e 's|
()
|
\1
|g' \ + -e 's|
()
|
\1
|g' \ + -e 's|
()
|
\1
|g' \ + -e 's|
()
|
\1
|g' \ + > "${DOCUMENT}.${MARSH_UID}.document" fi # unset temporary global variables