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,7 +8,8 @@
# Date: 2024-03 # Date: 2024-03
#――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
POST_TEMPLATE=' if test -z "$POST_TEMPLATE"; then
POST_TEMPLATE='
<article class="comment"> <article class="comment">
<a class="user" href="$ACCOUNT_URL"> <a class="user" href="$ACCOUNT_URL">
<img class="avatar" src="$ACCOUNT_AVATAR"> <img class="avatar" src="$ACCOUNT_AVATAR">
@ -29,17 +30,21 @@ POST_TEMPLATE='
</div> </div>
</article> </article>
' '
fi
if test -z "$ATTACH_TEMPLATE"; then
ATTACH_TEMPLATE=' ATTACH_TEMPLATE='
<a href="$ATTACH_URL"> <a href="$ATTACH_URL">
<div class="attachment"> <div class="attachment">
<strong>$ATTACH_NAME</strong> <strong>$ATTACH_NAME</strong>
$ATTACH_DESC $ATTACH_DESC
</div> </div>
</a>' </a>'
fi
ATTACH_IMAGE_TEMPLATE='
if test -z "$ATTACH_IMAGE_TEMPLATE"; then
ATTACH_IMAGE_TEMPLATE='
<figure> <figure>
<a href="$ATTACH_URL"> <a href="$ATTACH_URL">
<img class="attachment" src="$ATTACH_URL" alt="$ATTACH_DESC" title="$ATTACH_DESC"> <img class="attachment" src="$ATTACH_URL" alt="$ATTACH_DESC" title="$ATTACH_DESC">
@ -55,8 +60,12 @@ ATTACH_IMAGE_TEMPLATE='
</figcaption> </figcaption>
</figure> </figure>
' '
fi
EMOJI_TEMPLATE='<img class="emoji" src="$EMOJI_URL" alt="$EMOJI_SHORTCODE" title="$EMOJI_SHORTCODE">'
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. # Given a notes JSON, render it as HTML.
@ -345,7 +354,18 @@ usage() {
echo " $(basename "$0") [-h] [-IRc] [-bBt] USER_URL" echo " $(basename "$0") [-h] [-IRc] [-bBt] USER_URL"
echo echo
echo "$(basename "$0") does exactly what it says on the tin: It formats" 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 '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'
echo ' -I display posts in reverse-chronological order'
echo ' -l output at maximum the specified amount of posts'
echo ' -R do not recursively display posts responses'
echo
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
echo 'It works with posts from any server that supports Mastodons API,' echo 'It works with posts from any server that supports Mastodons API,'
echo 'including Pleroma, Akkoma, Glitch, etc.' echo 'including Pleroma, Akkoma, Glitch, etc.'
@ -355,15 +375,26 @@ usage() {
echo 'if privacy or total archival, is a concern, to use wget(1)s --mirror' 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 '(or something like it) to fetch even these foreign files.'
echo echo
echo ' -c only print the responses (children) of a post' echo '“Template” environment variables are used to generate the text'
echo ' -h print this message and exit' echo 'output. A template is a string that contains shell-style variable'
echo ' -I display posts in reverse-chronological order' echo "names (\$NAME) that $(basename "$0") will replace."
echo ' -l output at maximum the specified amount of posts' echo 'They are $POST_TEMPLATE, $ATTACH_TEMPLATE, and $EMOJI_TEMPLATE.'
echo ' -R do not recursively display posts responses' echo
echo echo 'The variables that can be used in $POST_TEMPLATE are:'
echo ' -b exclude reblogs/repeats from user feed' echo ' $ACCOUNT_ID, $ACCOUNT_URL, $ACCOUNT_NAME, $ACCOUNT_AVATAR,'
echo ' -B exclude top-level replies from user feed' echo ' $POST_URL, $POST_DATE, $POST_CONTENT, $POST_ATTACHMENTS,'
echo ' -t filter posts from user feed by tag' 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.'
} }