esh - simple template system based on shell
esh (embedded shell) is a templating engine for
evaluating shell commands embedded in arbitrary
templates.
esh converts template file, or stdin if file is
“-”, into a sequence of shell commands. Commands
between <% and %> tags are passed as-is,
everything else is escaped and prefixed with
printf command.
Example
esh \
-o "docs/posts/$id/index.html" \
"./post.esh" \
file="$file" \
date="$post_date" \
title="$post_title" \
read_time="$r_time" \
height="$height" \
intro="$(intro)"
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/syntax.css">
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1">
<meta content="#ffffff" name="theme-color">
<meta name="HandheldFriendly" content="true">
<meta property="og:title" content="<%=$title%>">
<meta property="og:type" content="website">
<meta property="og:description" content="a static site {for, by, about} me ">
<meta property="og:url" content="https://peppe.rs">
<link rel="icon" type="image/x-icon" href="/favicon.png">
<title><%=$title%> · peppe.rs</title>
<body>
<div class="posts">
<div class="post">
<a href="/" class="post-end-link">⟵ Back</a>
<a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/<% basename $file%>">View Raw</a>
<div class="separator"></div>
<div class="date">
<%="$date"%>
<div class="stats">
<span class="stats-number">
<%="$height"%>
</span>
<span class="stats-unit">cm</span>
 
<span class="stats-number">
<%="$read_time"%>
</span>
<span class="stats-unit">min</span>
</div>
</div>
<h1>
<%=$title%>
</h1>
<div class="post-text">
<% pandoc --quiet -t html --highlight-style monochrome "$file" %>
</div>
<%= "$intro" %>
<a href="/" class="post-end-link">⟵ Back</a>
<a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/<% basename $file%>">View Raw</a>
</div>
</div>
</body>
</html>
# generate rss feeds
echo "generating RSS feeds ..."
esh \
-o "./docs/index.xml" \
"rss.esh"
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>nerdypepper's μblog</title>
<link>https://peppe.rs</link>
<description>programming, design, software</description>
<atom:link href="https://peppe.rs/index.xml" rel="self" type="application/rss+xml" />
<image>
<title>nerdypepper's μblog</title>
<url>https://u.peppe.rs/n.png</url>
<link>https://peppe.rs</link>
</image>
<language>en-us</language>
<copyright>Creative Commons BY-NC-SA 4.0</copyright>
<% for f in `ls -t ./posts`; do
file="./posts/"$f
post_date=$(date -u -r "$file" "+%a, %d %b %Y %H:%M:00 %z")
html=$(pandoc -t html "$file" | sed -e "s/&/\&/g" -e "s/</\</g" -e "s/>/\>/g")
id="${file##*/}"
id="${id%.*}"
post_title=$(echo "$id" | sed -E -e "s/\..+$//g" -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g")
post_link="https://peppe.rs/posts/$id/"
echo "<item>"
echo "<title>$post_title</title>"
echo "<description>$html</description>"
echo "<link>$post_link</link>"
echo "<pubDate>$post_date</pubDate>"
echo "<guid>$post_link</guid>"
echo "</item>"
done
%>
</channel>
</rss>