http: builds blogs from gemlogs

This commit is contained in:
2026-06-09 16:11:06 +01:00
parent 3ecf19cb8a
commit b4f9be57d3
11 changed files with 414 additions and 16 deletions
+2
View File
@@ -1,2 +1,4 @@
out out
vendor vendor
src/microlog
src/blog
+12 -2
View File
@@ -1,8 +1,18 @@
all: clean out all: clean out
out: $(shell find src -type f) $(shell find share -type f) $(shell find bin) out: microlog blog $(shell find src -type f) $(shell find share -type f) $(shell find bin)
./bin/mkws https://joeac.net ./bin/mkws https://joeac.net
microlog: src/microlog
src/microlog: $(shell find -L blogs/microlog -type f) bin/blog
./bin/blog -i microlog -l microlog -t
blog: src/blog
src/blog: $(shell find -L blogs/blog -type f) bin/blog
./bin/blog -i blog -l blog
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf out rm -rf out src/microlog src/blog
Executable
+88
View File
@@ -0,0 +1,88 @@
#!/bin/sh -e
export PATH="$(dirname $(realpath $0)):$PATH"
export BLOGS="$(realpath blogs)"
export SRC="$(realpath src)"
export LAYOUTS="$(realpath share/layouts)"
usage()
{
>&2 cat << USAGE
usage: blog -i LOG [-l LAYOUT] [-t]
options:
-i LOG
The name of the source directory under \$BLOGS where log posts live.
-l LAYOUT
If provided, the layout under \$LAYOUTS to use for the generated
upphtml files. If not provided, uses the default layout.
-t
If enabled, use filenames as post titles
USAGE
}
log_name=""
layout="default"
use_filenames_for_titles=0
while getopts "i:l:t" opt
do
case $opt in
i)
log_name="$OPTARG"
;;
l)
layout_name="$OPTARG"
;;
t)
use_filenames_for_titles=1
;;
esac
done
if [ -z "${log_name}" ]
then
usage
exit 1
fi
if ! [ -d "${BLOGS}/${log_name}" ]
then
>&2 echo "there is no directory '${input_log}' under ${BLOGS}. options: $(ls common)"
usage
exit 1
fi
layout="${LAYOUTS}/${layout_name}.layout.upphtml"
if [ "${layout_name}" = "default" ]
then
layout_ext=""
else
layout_ext=".${layout_name}"
fi
if ! [ -f "${layout}" ]
then
echo >&2 "Warning: no layout found at $(basename "${LAYOUTS}")/${layout_name}.layout.upphtml"
fi
rm -rf "${SRC}/${log_name}/"
mkdir -p "${SRC}/${log_name}"
for entry in $(find -L "${BLOGS}/${log_name}" -type f)
do
basename="$(basename "$entry")"
name="${basename%%\.*}"
dest="${SRC}/${log_name}/${name}${layout_ext}.upphtml"
if [ $use_filenames_for_titles -eq 1 ]
then
title="$name"
cat "$entry" | gmi2upphtml "$title" > "$dest"
else
title="$(grep --regexp "^\# " --max-count 1 "$entry" | cut -c3-)"
cat "$entry" | grep --regexp "^\# " --invert-match | gmi2upphtml "$title" > "$dest"
fi
echo "${title}" > "${dest}.args"
echo "Processed ${entry#$(dirname ${BLOGS})/} to ${dest#$(dirname ${SRC})/}"
done
+176
View File
@@ -0,0 +1,176 @@
#!/bin/sh -e
post_title="${1:-}"
is_in_list=0
is_in_link_block=0
is_in_preformatted_block=0
is_in_blockquote=0
if_in_list_then_close()
{
if [ $is_in_list -ne 0 ]
then
echo "</ul>"
is_in_list=0
fi
}
if_in_link_block_then_close()
{
if [ $is_in_link_block -ne 0 ]
then
echo "</p>"
is_in_link_block=0
fi
}
if_in_preformatted_block_then_close()
{
if [ $is_in_preformatted_block -ne 0 ]
then
echo "</pre>"
is_in_preformatted_block=0
fi
}
if_in_blockquote_then_close()
{
if [ $is_in_blockquote -ne 0 ]
then
echo "</blockquote>"
is_in_blockquote=0
fi
}
close_all_open_blocks()
{
if_in_list_then_close
if_in_link_block_then_close
if_in_preformatted_block_then_close
if_in_blockquote_then_close
}
escape_upphtml()
{
echo "$1" | sed "s/\`/\\\\\`/g" | sed "s/\"/\\\\\"/g" | sed "s/\\\$/\\\\\$/g"
}
close_all_open_blocks_except()
{
except="$1"
if [ "$except" != "list" ]
then
if_in_list_then_close
fi
if [ "$except" != "link" ]
then
if_in_link_block_then_close
fi
if [ "$except" != "pre" ]
then
if_in_preformatted_block_then_close
fi
if [ "$except" != "blockquote" ]
then
if_in_blockquote_then_close
fi
}
if [ -z "$post_title" ]
then
read first_line
if [ "$(echo "$first_line" | cut -c1-2)" != "# " ]
then
echo >&2 "Error: no [post_title] argument provided and no top-level heading at top of the document."
exit 1
fi
post_title="${first_line### }"
fi
echo "#!
export TITLE=\"${post_title} | joeac's blog\"
export DESCRIPTION=\"${post_title} | joeac's blog\"
pp \"\${SHARE}\"/components/meta.upphtml
#!"
while read line
do
if [ "$(echo $line | sed "s/[[:space:]]//g")" = "" ]
then
continue
fi
if [ "$(echo $line | cut -c1)" = "#" ]
then
title="$(escape_upphtml "${line#*# }")"
heading="${line%%$title}"
heading="${heading%% }"
heading_level="${#heading}"
if [ "$(echo "$line" | cut -c$(( $heading_level + 1 )) )" = " " ]
then
close_all_open_blocks
echo "<h${heading_level}>${title}</h${heading_level}>"
continue
fi
fi
if [ "$(echo "$line" | cut -c1-2)" = "=>" ]
then
close_all_open_blocks_except link
href="$(escape_upphtml "$(echo "$line" | sed "s/^=>[[:space:]]*\([[:alnum:][:punct:]]\+\).*$/\1/")")"
title="$(escape_upphtml "$(echo "$line" | sed "s/^=>[[:space:]]*[[:alnum:][:punct:]]\+[[:space:]]\(.*\)$/\1/")")"
if [ $is_in_link_block -eq 0 ]
then
echo "<p>"
else
echo "<br/>"
fi
is_in_link_block=1
echo "=> <a href='${href}'>${title}</a>"
continue
fi
if [ "$( echo "$line" | cut -c1-2)" = "* " ]
then
close_all_open_blocks_except list
if [ $is_in_list -eq 0 ]
then
echo "<ul>"
fi
is_in_list=1
echo "<li>$(escape_upphtml "$(echo "$line" | cut -c3-)")</li>"
continue
fi
if [ "$(echo "$line" | cut -c1)" = ">" ]
then
close_all_open_blocks_except blockquote
if [ $is_in_blockquote -eq 0 ]
then
echo "<blockquote>"
fi
is_in_blockquote=1
echo "<p>$(escape_upphtml "$(echo "$line" | cut -c2-)")</p>"
continue
fi
if [ "$(echo "$line" | cut -c1-3)" = "\`\`\`" ]
then
close_all_open_blocks_except pre
if [ $is_in_preformatted_block -eq 0 ]
then
echo "<pre>"
else
echo -e "\n"
fi
is_in_preformatted_block=1
echo "$(escape_upphtml "$(echo "$line" | cut -c4-)")"
continue
fi
close_all_open_blocks
echo "<p>$(escape_upphtml "${line}")</p>"
done
close_all_open_blocks
+30 -14
View File
@@ -11,6 +11,8 @@ test $# -lt 1 && usage
export SRC="$(realpath src)" export SRC="$(realpath src)"
export PUBLIC="$(realpath public)" export PUBLIC="$(realpath public)"
export SHARE="$(realpath share)" export SHARE="$(realpath share)"
export LAYOUTS="$(realpath share/layouts)"
export DEFAULT_LAYOUT="${LAYOUTS}/default.layout.upphtml"
export OUT="$(realpath out)" export OUT="$(realpath out)"
if [ -d "${PUBLIC}" ] if [ -d "${PUBLIC}" ]
@@ -28,22 +30,36 @@ then
exit 1 exit 1
fi fi
for t in "${SRC}"/*.upphtml for t in $(find -L "${SRC}/" -type f -and -name "*\.upp*" -and -not -name "*\.upp*\.*")
do do
echo "Making $(basename "${t%.upphtml}".html)" basename="$(basename "$t")"
pp "${SHARE}"/l.upphtml "${t}" "$1" > \ ext="${basename##*upp}"
"${OUT}/$(basename "${t%.upphtml}".html)"
done
for t in "${SRC}"/**/*.uppcss basename_without_ext="${basename%\.upp${ext}}"
do penultimate_segment="${basename_without_ext##*\.}"
t_out="${t%.uppcss}".css if [ "$basename_without_ext" != "$penultimate_segment" ] && [ -f "${LAYOUTS}/${penultimate_segment}.layout.upphtml" ]
t_out="${t_out#${SRC}/}" then
echo "Making ${t_out}" layout="${LAYOUTS}/${penultimate_segment}.layout.upphtml"
t_out="${OUT}/${t_out}" name="${basename%\.${penultimate_segment}\.upp${ext}}"
mkdir -p "$(dirname "${t_out}")" else
pp "${t}" "$1" > \ layout="${DEFAULT_LAYOUT}"
"${t_out}" name="${basename%\.upp${ext}}"
fi
in_dir="$(dirname "$t")/"
rel_dir="${in_dir#${SRC}/}"
mkdir -p "${OUT}/${rel_dir}/"
args="$( [ -f "${t}.args" ] && cat "${t}.args" || echo "" )"
if [ "$ext" = "html" ]
then
pp "${layout}" "${t}" "$1" "$args" > \
"${OUT}/${rel_dir}/${name}.${ext}"
else
pp "${t}" "$1" "$args" > \
"${OUT}/${rel_dir}/${name}.${ext}"
fi
echo "Written ${OUT}/${rel_dir}${name}.${ext}"
done done
echo "Making sitemap.xml" echo "Making sitemap.xml"
+1
View File
@@ -0,0 +1 @@
../../common/longlog/
+1
View File
@@ -0,0 +1 @@
../../common/microlog/
@@ -0,0 +1,4 @@
#!
FORMATTED_DATE="$(date --date "${DATE}" +'%A %-d %B %Y')"
echo "<time datetime='${DATE}' class='${CLASS}' ${ATTRIBUTES}>${FORMATTED_DATE}</time>"
#!
+50
View File
@@ -0,0 +1,50 @@
#!
SRC="$1"
SITE_URL="$2"
POST_TITLE="$3"
DATE_PUBLISHED="$(basename "${SRC}" | cut -c1-10)"
CANONICAL_URL="${SITE_URL}/blog/$(basename "${SRC}")"
#!
<!doctype html>
<html lang="en-GB">
<head>
#!
pp "${SHARE}"/components/head.upphtml
#!
</head>
<body>
#!
pp "${SHARE}"/components/navbar.upphtml
#!
<article class='h-entry'>
<aside>
<span>This is a blog post by <a class='p-author h-card' href='/'>Joe Carstairs</a>.</span>
<span>Published:
#!
DATE="${DATE_PUBLISHED}" CLASS="dt-published" pp "${SHARE}/components/formatted_date.upphtml"
#!
.</span>
<span hidden><a class='u-url uid' href='${CANONICAL_URL}'>Permalink</a></span>
</aside>
<header>
<h1 class='h-name'>
#!
echo "${POST_TITLE}"
#!
</h1>
</header>
<section class='e-content'>
#!
pp "${SRC}"
#!
</section>
</article>
@@ -0,0 +1,50 @@
#!
SRC="$1"
SITE_URL="$2"
POST_TITLE="$3"
DATE_PUBLISHED="$(basename "${SRC}" | cut -c1-10)"
CANONICAL_URL="${SITE_URL}/microlog/$(basename "${SRC}")"
#!
<!doctype html>
<html lang="en-GB">
<head>
#!
pp "${SHARE}"/components/head.upphtml
#!
</head>
<body>
#!
pp "${SHARE}"/components/navbar.upphtml
#!
<article class="h-entry">
<aside>
<span>This is a microlog post by <a class='p-author h-card' href='/'>Joe Carstairs</a>.</span>
<span>Published:
#!
DATE="${DATE_PUBLISHED}" CLASS="dt-published" pp "${SHARE}/components/formatted_date.upphtml"
#!
.</span>
<span hidden><a class='u-url uid' href='${CANONICAL_URL}'>Permalink</a></span>
</aside>
<header>
<h1 class='h-name'>
#!
echo "${POST_TITLE}"
#!
</h1>
</header>
<section class="e-content">
#!
pp "${SRC}"
#!
</section>
</article>