build.sh (1642B)
1 #!/bin/bash 2 3 set -eu 4 5 input=$1 6 parameters=$2 7 template=$3 8 outdir=$4 9 uri=$5 10 output="${outdir}/${uri}" 11 12 . settings.sh 13 14 cp ${template} ${output} 15 16 transform-li-current-a () 17 { 18 local old="<li><a href=\"$1.html\">" 19 local new="<li><a class=\"current\" href=\"$1.html\">" 20 echo "s/${old}/${new}/" 21 } 22 23 transform-li-dropdown-current-a () 24 { 25 local old="<li class=\"dropdown\"><a href=\"$1.html\">" 26 local new="<li class=\"dropdown\"><a class=\"current\" href=\"$1.html\">" 27 echo "s/${old}/${new}/" 28 } 29 30 transforms=() 31 postprocess=true 32 iconcolor= 33 . ${parameters} 34 35 sed -i s/'{TITLE}'/"${title}"/ ${output} 36 37 sed -i s,'{URI}',"${uri}", ${output} 38 sed -i s,'{DOMAIN}',"${domain}", ${output} 39 40 link_stylesheets='' 41 for s in "${stylesheets[@]}" 42 do 43 # Prefer relative paths so that drafts under /admin/drafts find 44 # the correct stylesheets. 45 # ${input} might be a temporary file; assume ${template} is a 46 # bona-fide node in our directory hierarchy, and use that to 47 # compute the path to the stylesheets folder. 48 spath=$(realpath --relative-to $(dirname "${template}") stylesheets/"${s}".css) 49 link_template='<link rel="stylesheet" href="%s">\n' 50 link_stylesheets+=$(printf "${link_template}" "${spath}") 51 done 52 53 sed -i /'{STYLESHEETS}'/'c\'"${link_stylesheets}" ${output} 54 55 sed -i s/'{TRANSLATION}'/"${translation}"/ ${output} 56 57 for transform in "${transforms[@]}" 58 do 59 sed -i "${transform}" ${output} 60 done 61 62 if test "${iconcolor}" 63 then 64 sed -i s/'{ICONCOLOR}'/"-${iconcolor}"/ ${output} 65 else 66 sed -i s/'{ICONCOLOR}'// ${output} 67 fi 68 69 sed -i -e /'{MAIN}'/"r ${input}" -e /'{MAIN}'/'c\' ${output} 70 71 ${postprocess} ${output}