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.
This commit is contained in:
Bradley Sepos 2018-01-25 04:52:16 -05:00
parent 26e4bfc9eb
commit 3fd004b08d
No known key found for this signature in database
GPG Key ID: DEADE2F57D42D9C7

20
marsh
View File

@ -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|^!\[(.+)]\([ ]*([^ ]+)[ ]*"(.+)"[ ]*\)$|<figure><a href="\2"><img src="\2" alt="\1" /></a><figcaption>\3</figcaption></figure>|' |
process_markdown > "${DOCUMENT}.${MARSH_UID}.document"
-e 's|^!\[(.+)]\([ ]*([^ ]+)[ ]*"(.+)"[ ]*\)$|<figure><img src="\2" alt="\1" /><figcaption>\3</figcaption></figure>|' |
process_markdown |
sed -E \
-e 's|<p><figure>|<figure>|' \
-e 's|</figure></p>|</figure>|' |
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|<figure>(<img[ ]+src="[^"]+"[ ]+srcset="[^"]+[ ]+1x,[ ]*[^"]+[ ]+2x,[ ]*([^"]+)[ ]+3x"[ ]+alt="[^"]+"[ ]*/?[ ]*>)<figcaption>|<figure><a href="\2">\1</a><figcaption>|g' \
-e 's|<figure>(<img[ ]+src="[^"]+"[ ]+srcset="[^"]+[ ]+1x,[ ]*([^"]+)[ ]+2x"[ ]*alt="[^"]+"[ ]+/?[ ]*>)<figcaption>|<figure><a href="\2">\1</a><figcaption>|g' \
-e 's|<figure>(<img[ ]+src="[^"]+"[ ]+srcset="([^"]+)[ ]+1x"[ ]*alt="[^"]+"[ ]*/?[ ]*>)<figcaption>|<figure><a href="\2">\1</a><figcaption>|g' \
-e 's|<figure>(<img[ ]+src="([^"]+)"([ ]+srcset="[^"]*")*[ ]*alt="[^"]+"[ ]*/?[ ]*>)<figcaption>|<figure><a href="\2">\1</a><figcaption>|g' \
> "${DOCUMENT}.${MARSH_UID}.document"
fi
# unset temporary global variables