-
Notifications
You must be signed in to change notification settings - Fork 0
/
posts.sh
executable file
·40 lines (32 loc) · 778 Bytes
/
posts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
title() {
title=$(awk '/<pmeta id="title">/{ gsub(/<[^>]*>/, ""); print }' "$1")
title=${title:-$(awk '/<title>/{ gsub(/<[^>]*>/, ""); print }' "$1")}
if [ -n "$title" ]; then
echo "$title"
else
echo "$1" |sed 's/\.md//g; s/^........-//g'
fi
}
created() {
created=$(awk '/<pmeta id="created">/{ gsub(/<[^>]*>/, ""); print }' "$1")
created=${created:-$(awk '/<created>/{ sub(/<[^>]*>/, ""); sub(/<.*/, ""); print }' "$1")}
echo "$created"
}
html() {
echo "$1" |sed 's/\.md/.html/'
}
if [ "$1" != "embed" ]; then
cat <<HEADER
Some blog posts
===============
HEADER
else
echo "Some blog posts:"
fi
while read post; do
echo "- $(created "$post") [$(title "$post")]($(html "$post"))"
done
if [ "$1" = "embed" ]; then
echo "- [all...](posts.html)"
fi