Allow overriding of templates; document in usage()

This commit is contained in:
Jaidyn Ann 2024-04-25 22:13:52 -05:00
parent 59edf2cdfb
commit 58797c1b3a

View File

@ -8,6 +8,7 @@
# Date: 2024-03
#―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
if test -z "$POST_TEMPLATE"; then
POST_TEMPLATE='
<article class="comment">
<a class="user" href="$ACCOUNT_URL">
@ -29,8 +30,9 @@ POST_TEMPLATE='
</div>
</article>
'
fi
if test -z "$ATTACH_TEMPLATE"; then
ATTACH_TEMPLATE='
<a href="$ATTACH_URL">
<div class="attachment">
@ -38,7 +40,10 @@ ATTACH_TEMPLATE='
$ATTACH_DESC
</div>
</a>'
fi
if test -z "$ATTACH_IMAGE_TEMPLATE"; then
ATTACH_IMAGE_TEMPLATE='
<figure>
<a href="$ATTACH_URL">
@ -55,8 +60,12 @@ ATTACH_IMAGE_TEMPLATE='
</figcaption>
</figure>
'
fi
if test -z "$EMOJI_TEMPLATE"; then
EMOJI_TEMPLATE='<img class="emoji" src="$EMOJI_URL" alt="$EMOJI_SHORTCODE" title="$EMOJI_SHORTCODE">'
fi
# Given a notes JSON, render it as HTML.
@ -345,15 +354,8 @@ usage() {
echo " $(basename "$0") [-h] [-IRc] [-bBt] USER_URL"
echo
echo "$(basename "$0") does exactly what it says on the tin: It formats"
echo 'a fediverse post (and its replies) into simple-and-embeddable HTML.'
echo
echo 'It works with posts from any server that supports Mastodons API,'
echo 'including Pleroma, Akkoma, Glitch, etc.'
echo
echo 'Notably, it supports post-atachments and custom-emoji. Keep in mind'
echo 'that images are all fetched from remote sources. It is recommended,'
echo 'if privacy or total archival, is a concern, to use wget(1)s --mirror'
echo '(or something like it) to fetch even these foreign files.'
echo 'a fediverse post (and its replies) into text. By default, into'
echo 'simple-and-embeddable HTML.'
echo
echo ' -c only print the responses (children) of a post'
echo ' -h print this message and exit'
@ -364,6 +366,35 @@ usage() {
echo ' -b exclude reblogs/repeats from user feed'
echo ' -B exclude top-level replies from user feed'
echo ' -t filter posts from user feed by tag'
echo
echo 'It works with posts from any server that supports Mastodons API,'
echo 'including Pleroma, Akkoma, Glitch, etc.'
echo
echo 'Notably, it supports post-atachments and custom-emoji. Keep in mind'
echo 'that images are all fetched from remote sources. It is recommended,'
echo 'if privacy or total archival, is a concern, to use wget(1)s --mirror'
echo '(or something like it) to fetch even these foreign files.'
echo
echo '“Template” environment variables are used to generate the text'
echo 'output. A template is a string that contains shell-style variable'
echo "names (\$NAME) that $(basename "$0") will replace."
echo 'They are $POST_TEMPLATE, $ATTACH_TEMPLATE, and $EMOJI_TEMPLATE.'
echo
echo 'The variables that can be used in $POST_TEMPLATE are:'
echo ' $ACCOUNT_ID, $ACCOUNT_URL, $ACCOUNT_NAME, $ACCOUNT_AVATAR,'
echo ' $POST_URL, $POST_DATE, $POST_CONTENT, $POST_ATTACHMENTS,'
echo ' and $POST_RESPONSES.'
echo
echo 'The variables that can be used in $ATTACH_TEMPLATE are:'
echo ' $ATTACH_URL, $ATTACH_NAME, $ATTACH_TYPE, $ATTACH_DESC,'
echo ' and $ATTACH_PREVIEW.'
echo
echo 'The variables that can be used in $EMOJI_TEMPLATE are:'
echo ' $EMOJI_SHORTCODE and $EMOJI_URL.'
echo
echo 'See the first few lines of fedi2html for the default (example)'
echo 'template values; see the README for a more detailed description'
echo 'of these variables meanings.'
}