Compare commits

...

9 Commits

9 changed files with 137 additions and 21 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# Hararis Sapiens on Religion # Hararis Sapiens on Religion
Published: 14 Jan 2024 Published on: 14 Jan 2024
Ive been slowly re-reading Yuval Noah Hararis 2014 classic, Sapiens, which apart from being ridiculously over-scoped and hilariously under-evidenced, is proving delightfully entertaining. Ive been slowly re-reading Yuval Noah Hararis 2014 classic, Sapiens, which apart from being ridiculously over-scoped and hilariously under-evidenced, is proving delightfully entertaining.
+2 -2
View File
@@ -6,12 +6,12 @@ out: microlog blog $(shell find src -type f) $(shell find share -type f) $(shell
microlog: src/microlog microlog: src/microlog
src/microlog: $(shell find -L blogs/microlog -type f) bin/blog src/microlog: $(shell find -L blogs/microlog -type f) bin/blog
./bin/blog -i microlog -l microlog -t ./bin/blog -i microlog -l microlog -t -p gmi2upphtml
blog: src/blog blog: src/blog
src/blog: $(shell find -L blogs/blog -type f) bin/blog src/blog: $(shell find -L blogs/blog -type f) bin/blog
./bin/blog -i blog -l blog ./bin/blog -i blog -l blog -p 'cut_longlog_meta | gmi2upphtml' -a extract_longlog_meta
.PHONY: clean .PHONY: clean
clean: clean:
+22 -5
View File
@@ -7,10 +7,14 @@ export LAYOUTS="$(realpath share/layouts)"
usage() usage()
{ {
>&2 cat << USAGE >&2 cat << USAGE
usage: blog -i LOG [-l LAYOUT] [-t] usage: blog -i LOG [-p POSTPROCESS_CMD] [-a EXTRACT_ARGS_CMD] [-l LAYOUT] [-t]
options: options:
-a EXTRACT_ARGS_CMD
If provided, a shell command to extract arguments to the layout from the
source files. The shell will be provided with a variable, POST_TITLE.
-i LOG -i LOG
The name of the source directory under \$BLOGS where log posts live. The name of the source directory under \$BLOGS where log posts live.
@@ -18,24 +22,36 @@ options:
If provided, the layout under \$LAYOUTS to use for the generated If provided, the layout under \$LAYOUTS to use for the generated
upphtml files. If not provided, uses the default layout. upphtml files. If not provided, uses the default layout.
-p POSTPROCESS_CMD
If provided, a shell command to post-process the source files into
upphtml. The shell will be provided with a variable, POST_TITLE.
-t -t
If enabled, use filenames as post titles If enabled, use filenames as post titles
USAGE USAGE
} }
extract_args_cmd="head -n 0 | echo \"POST_TITLE=\\\"\${POST_TITLE}\\\"\""
log_name="" log_name=""
layout="default" layout="default"
postprocess_cmd="echo"
use_filenames_for_titles=0 use_filenames_for_titles=0
while getopts "i:l:t" opt while getopts "a:i:l:p:t" opt
do do
case $opt in case $opt in
a)
extract_args_cmd="$OPTARG"
;;
i) i)
log_name="$OPTARG" log_name="$OPTARG"
;; ;;
l) l)
layout_name="$OPTARG" layout_name="$OPTARG"
;; ;;
p)
postprocess_cmd="$OPTARG"
;;
t) t)
use_filenames_for_titles=1 use_filenames_for_titles=1
;; ;;
@@ -78,11 +94,12 @@ do
if [ $use_filenames_for_titles -eq 1 ] if [ $use_filenames_for_titles -eq 1 ]
then then
title="$name" title="$name"
cat "$entry" | gmi2upphtml "$title" > "$dest" cat "$entry" | eval "POST_TITLE=\"${title}\" ${postprocess_cmd}" > "$dest"
else else
title="$(grep --regexp "^\# " --max-count 1 "$entry" | cut -c3-)" title="$(grep --regexp "^\# " --max-count 1 "$entry" | cut -c3-)"
cat "$entry" | grep --regexp "^\# " --invert-match | gmi2upphtml "$title" > "$dest" export POST_TITLE="$title"
cat "$entry" | grep --regexp "^\# " --invert-match | eval "$postprocess_cmd" > "$dest"
fi fi
echo "${title}" > "${dest}.args" cat "$entry" | eval "$extract_args_cmd" > "${dest}.args"
echo "Processed ${entry#$(dirname ${BLOGS})/} to ${dest#$(dirname ${SRC})/}" echo "Processed ${entry#$(dirname ${BLOGS})/} to ${dest#$(dirname ${SRC})/}"
done done
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh -e
meta=""
read_published_on=0
while read line
do
meta="${meta}
${line}"
if [ "$(echo "$line" | cut -c1-14)" = "Published on: " ]
then
read_published_on=1
break
fi
done
if [ "$read_published_on" -eq 0 ]
then
echo "$meta"
exit 0
fi
read line
if [ "$(echo "$line" | cut -c1-14)" = "Updated: " ]
then
meta="${meta}
${line}"
else
echo "$line"
fi
while read line
do
echo "$line"
done
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh -e
POST_TITLE="${POST_TITLE:-}"
DATE_PUBLISHED=""
DATE_UPDATED=""
while read line
do
if [ "$(echo "$line" | cut -c1-2)" = "# " ]
then
POST_TITLE="$(echo "$line" | cut -c3-)"
elif [ "$(echo "$line" | cut -c1-14)" = "Published on: " ]
then
DATE_PUBLISHED="$(date --date="$(echo "$line" | cut -c15-)" +%Y-%m-%d)"
elif [ "$(echo "$line" | cut -c1-12)" = "Updated on: " ]
then
DATE_UPDATED="$(date --date="$(echo "$line" | cut -c13-)" +%Y-%m-%d)"
fi
done
if [ -n "$POST_TITLE" ]
then
echo "POST_TITLE=\"${POST_TITLE}\""
fi
if [ -n "$DATE_PUBLISHED" ]
then
echo "DATE_PUBLISHED=\"${DATE_PUBLISHED}\""
fi
if [ -n "$DATE_UPDATED" ]
then
echo "DATE_UPDATED=\"${DATE_UPDATED}\""
fi
+4 -3
View File
@@ -1,6 +1,6 @@
#!/bin/sh -e #!/bin/sh -e
post_title="${1:-}" post_title="${POST_TITLE:-}"
is_in_list=0 is_in_list=0
is_in_link_block=0 is_in_link_block=0
@@ -118,8 +118,9 @@ do
if [ "$(echo "$line" | cut -c1-2)" = "=>" ] if [ "$(echo "$line" | cut -c1-2)" = "=>" ]
then then
close_all_open_blocks_except link close_all_open_blocks_except link
href="$(escape_upphtml "$(echo "$line" | sed "s/^=>[[:space:]]*\([[:alnum:][:punct:]]\+\).*$/\1/")")" href="$(escape_upphtml "$(echo "$line" | sed "s/^=>[[:space:]]\+//" | sed "s/[[:space:]]\+.*//")")"
title="$(escape_upphtml "$(echo "$line" | sed "s/^=>[[:space:]]*[[:alnum:][:punct:]]\+[[:space:]]\(.*\)$/\1/")")" title="$(escape_upphtml "${line#=> *${href}}")"
title="${title:-${href}}"
if [ $is_in_link_block -eq 0 ] if [ $is_in_link_block -eq 0 ]
then then
echo "<p>" echo "<p>"
+19 -2
View File
@@ -51,14 +51,31 @@ do
mkdir -p "${OUT}/${rel_dir}/" mkdir -p "${OUT}/${rel_dir}/"
args="$( [ -f "${t}.args" ] && cat "${t}.args" || echo "" )" args="$( [ -f "${t}.args" ] && cat "${t}.args" || echo "" )"
if [ "$(head -n 1 "${layout}")" = "#!" ]
then
>"${layout}.tmp" echo "
#!
${args}
$(tail -n +2 "${layout}")
"
else
>"${layout}.tmp" echo "
#!
${args}
#!
$(cat "${layout}")
"
fi
if [ "$ext" = "html" ] if [ "$ext" = "html" ]
then then
pp "${layout}" "${t}" "$1" "$args" > \ pp "${layout}.tmp" "${t}" "${1}" > \
"${OUT}/${rel_dir}/${name}.${ext}" "${OUT}/${rel_dir}/${name}.${ext}"
else else
pp "${t}" "$1" "$args" > \ pp "${t}" "${1}" > \
"${OUT}/${rel_dir}/${name}.${ext}" "${OUT}/${rel_dir}/${name}.${ext}"
fi fi
rm "${layout}.tmp"
echo "Written ${OUT}/${rel_dir}${name}.${ext}" echo "Written ${OUT}/${rel_dir}${name}.${ext}"
done done
+21 -7
View File
@@ -1,8 +1,7 @@
#! #!
SRC="$1" SRC="$1"
SITE_URL="$2" SITE_URL="$2"
POST_TITLE="$3" DATE_PUBLISHED="${DATE_PUBLISHED:-$(basename "${SRC}" | cut -c1-10)}"
DATE_PUBLISHED="$(basename "${SRC}" | cut -c1-10)"
CANONICAL_URL="${SITE_URL}/blog/$(basename "${SRC}")" CANONICAL_URL="${SITE_URL}/blog/$(basename "${SRC}")"
#! #!
@@ -25,20 +24,35 @@ pp "${SHARE}"/components/navbar.upphtml
<aside> <aside>
<span>This is a blog post by <a class='p-author h-card' href='/'>Joe Carstairs</a>.</span> <span>This is a blog post by <a class='p-author h-card' href='/'>Joe Carstairs</a>.</span>
#!
if [ -z "${DATE_UPDATED}" ]; then
#!
<span>Published: <span>Published:
#! #!
DATE="${DATE_PUBLISHED}" CLASS="dt-published" pp "${SHARE}/components/formatted_date.upphtml" DATE="${DATE_PUBLISHED}" CLASS="dt-published" pp "${SHARE}/components/formatted_date.upphtml"
#! #!
.</span> .</span>
#!
else
#!
<span>Updated:
#!
DATE="${DATE_UPDATED}" CLASS="dt-updated" pp "${SHARE}/components/formatted_date.upphtml"
#!
.</span>
<span>Originally published:
#!
DATE="${DATE_PUBLISHED}" CLASS="dt-published" pp "${SHARE}/components/formatted_date.upphtml"
#!
.</span>
#!
fi
#!
<span hidden><a class='u-url uid' href='${CANONICAL_URL}'>Permalink</a></span> <span hidden><a class='u-url uid' href='${CANONICAL_URL}'>Permalink</a></span>
</aside> </aside>
<header> <header>
<h1 class='h-name'> <h1 class='h-name'>${POST_TITLE}</h1>
#!
echo "${POST_TITLE}"
#!
</h1>
</header> </header>
<section class='e-content'> <section class='e-content'>
@@ -1,7 +1,6 @@
#! #!
SRC="$1" SRC="$1"
SITE_URL="$2" SITE_URL="$2"
POST_TITLE="$3"
DATE_PUBLISHED="$(basename "${SRC}" | cut -c1-10)" DATE_PUBLISHED="$(basename "${SRC}" | cut -c1-10)"
CANONICAL_URL="${SITE_URL}/microlog/$(basename "${SRC}")" CANONICAL_URL="${SITE_URL}/microlog/$(basename "${SRC}")"
#! #!