parameterises postprocess cmd in blog script

This commit is contained in:
2026-06-09 18:19:16 +01:00
parent b4f9be57d3
commit 0892937941
3 changed files with 16 additions and 7 deletions
+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
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
src/blog: $(shell find -L blogs/blog -type f) bin/blog
./bin/blog -i blog -l blog
./bin/blog -i blog -l blog -p gmi2upphtml
.PHONY: clean
clean:
Executable → Regular
+13 -4
View File
@@ -7,7 +7,7 @@ export LAYOUTS="$(realpath share/layouts)"
usage()
{
>&2 cat << USAGE
usage: blog -i LOG [-l LAYOUT] [-t]
usage: blog -i LOG [-p POSTPROCESS_CMD] [-l LAYOUT] [-t]
options:
@@ -18,6 +18,10 @@ options:
If provided, the layout under \$LAYOUTS to use for the generated
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
If enabled, use filenames as post titles
USAGE
@@ -25,9 +29,10 @@ USAGE
log_name=""
layout="default"
postprocess_cmd="echo"
use_filenames_for_titles=0
while getopts "i:l:t" opt
while getopts "i:l:p:t" opt
do
case $opt in
i)
@@ -36,6 +41,9 @@ do
l)
layout_name="$OPTARG"
;;
p)
postprocess_cmd="$OPTARG"
;;
t)
use_filenames_for_titles=1
;;
@@ -78,10 +86,11 @@ do
if [ $use_filenames_for_titles -eq 1 ]
then
title="$name"
cat "$entry" | gmi2upphtml "$title" > "$dest"
cat "$entry" | POST_TITLE="$title" eval "$postprocess_cmd" > "$dest"
else
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
echo "${title}" > "${dest}.args"
echo "Processed ${entry#$(dirname ${BLOGS})/} to ${dest#$(dirname ${SRC})/}"
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh -e
post_title="${1:-}"
post_title="${POST_TITLE:-}"
is_in_list=0
is_in_link_block=0