Support for displaying post attachments
… and some general tweaking of the default templates.
This commit is contained in:
parent
89120ccb73
commit
d8d85af234
75
fedi2html.sh
75
fedi2html.sh
|
@ -62,25 +62,53 @@ POST_TEMPLATE='
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<link rel="stylesheet" href="comments.css" type="text/css">
|
<link rel="stylesheet" href="comments.css" type="text/css">
|
||||||
<div id="comments">
|
<article class="comment">
|
||||||
<a class="comment-user" href="$ACCOUNT_URL">
|
<a class="user" href="$ACCOUNT_URL">
|
||||||
<img class="comment-avatar" src="$ACCOUNT_AVATAR">
|
<img class="avatar" src="$ACCOUNT_AVATAR">
|
||||||
<strong class="comment-username">$ACCOUNT_NAME</strong>
|
<strong class="username">$ACCOUNT_NAME</strong>
|
||||||
<em class="comment-useraddress">$ACCOUNT_ID</em>
|
<em class="useraddress">$ACCOUNT_ID</em>
|
||||||
</a>
|
</a>
|
||||||
<a class="comment-address" href="$POST_URL">
|
<a class="address" href="$POST_URL">
|
||||||
<time class="comment-time" title="$POST_DATE">$(date --date=$POST_DATE)</time>
|
<time title="$POST_DATE">$(date --date=$POST_DATE)</time>
|
||||||
</a>
|
</a>
|
||||||
<div class="comment-body">
|
<section>
|
||||||
$POST_CONTENT
|
$POST_CONTENT
|
||||||
|
</section>
|
||||||
|
<div class="attachments">
|
||||||
|
$POST_ATTACHMENTS
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</article>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
||||||
EMOJI_TEMPLATE='<img class="emoji" src="$EMOJI_URL" alt="$EMOJI_SHORTCODE">'
|
ATTACH_TEMPLATE='
|
||||||
|
<a href="$ATTACH_URL">
|
||||||
|
<div class="attachment">
|
||||||
|
<strong>$ATTACH_NAME</strong>
|
||||||
|
$ATTACH_DESC
|
||||||
|
</div>
|
||||||
|
</a>'
|
||||||
|
|
||||||
|
ATTACH_IMAGE_TEMPLATE='
|
||||||
|
<figure>
|
||||||
|
<a href="$ATTACH_URL">
|
||||||
|
<img class="attachment" src="$ATTACH_URL" alt="$ATTACH_DESC" title="$ATTACH_DESC">
|
||||||
|
</a>
|
||||||
|
<figcaption>
|
||||||
|
<a href="$ATTACH_URL"><b>$ATTACH_NAME</b></a><br>
|
||||||
|
$(if test $(echo "$ATTACH_DESC" | wc -c) -gt 52; then
|
||||||
|
echo $ATTACH_DESC | head -c 53 | sed 's%[[:space:]]*$%%'
|
||||||
|
echo …
|
||||||
|
else
|
||||||
|
echo $ATTACH_DESC
|
||||||
|
fi)
|
||||||
|
</figcaption>
|
||||||
|
</figure>
|
||||||
|
'
|
||||||
|
|
||||||
|
EMOJI_TEMPLATE='<img class="emoji" src="$EMOJI_URL" alt="$EMOJI_SHORTCODE" title="$EMOJI_SHORTCODE">'
|
||||||
|
|
||||||
replace_emojis() {
|
replace_emojis() {
|
||||||
local post_data="$1"
|
local post_data="$1"
|
||||||
|
@ -91,8 +119,8 @@ replace_emojis() {
|
||||||
cat > "$temp"
|
cat > "$temp"
|
||||||
|
|
||||||
for line in $emojis; do
|
for line in $emojis; do
|
||||||
local EMOJI_URL="$(echo "$line" | awk '{print $1}')"
|
local EMOJI_URL="$(echo "$line" | awk -F'\t' '{print $1}')"
|
||||||
local EMOJI_SHORTCODE="$(echo "$line" | awk '{print $2}')"
|
local EMOJI_SHORTCODE="$(echo "$line" | awk -F'\t' '{print $2}')"
|
||||||
local value="$(env_subst "$EMOJI_TEMPLATE")"
|
local value="$(env_subst "$EMOJI_TEMPLATE")"
|
||||||
sed -i "s%:${EMOJI_SHORTCODE}:%${value}%g" "$temp"
|
sed -i "s%:${EMOJI_SHORTCODE}:%${value}%g" "$temp"
|
||||||
done
|
done
|
||||||
|
@ -100,6 +128,28 @@ replace_emojis() {
|
||||||
rm "$temp"
|
rm "$temp"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
media_attachments() {
|
||||||
|
local post_data="$1"
|
||||||
|
local attachments="$(echo "$post_data" | jq -r '.media_attachments[]|(.type + "\t" + .url + "\t" + .description + "\t" + .preview_url)')"
|
||||||
|
local IFS="
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "$attachments" > /tmp/d
|
||||||
|
for line in $attachments; do
|
||||||
|
local ATTACH_TYPE="$(echo "$line" | awk -F'\t' '{print $1}')"
|
||||||
|
local ATTACH_URL="$(echo "$line" | awk -F'\t' '{print $2}')"
|
||||||
|
local ATTACH_DESC="$(echo "$line" | awk -F'\t' '{print $3}')"
|
||||||
|
local ATTACH_PREVIEW="$(echo "$line" | awk -F'\t' '{print $4}')"
|
||||||
|
local ATTACH_NAME="$(basename "$ATTACH_URL")"
|
||||||
|
if test "$ATTACH_TYPE" = "image"; then
|
||||||
|
env_subst "$ATTACH_IMAGE_TEMPLATE"
|
||||||
|
else
|
||||||
|
env_subst "$ATTACH_TEMPLATE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
prep_template() {
|
prep_template() {
|
||||||
local template="$1"
|
local template="$1"
|
||||||
echo "$template" \
|
echo "$template" \
|
||||||
|
@ -120,6 +170,7 @@ render_post() {
|
||||||
local POST_URL="$(echo "$post_data" | jq -r .url)"
|
local POST_URL="$(echo "$post_data" | jq -r .url)"
|
||||||
local POST_DATE="$(echo "$post_data" | jq -r .created_at)"
|
local POST_DATE="$(echo "$post_data" | jq -r .created_at)"
|
||||||
local POST_CONTENT="$(echo "$post_data" | jq -r .content | replace_emojis "$post_data")"
|
local POST_CONTENT="$(echo "$post_data" | jq -r .content | replace_emojis "$post_data")"
|
||||||
|
local POST_ATTACHMENTS="$(media_attachments "$post_data")"
|
||||||
env_subst "$POST_TEMPLATE"
|
env_subst "$POST_TEMPLATE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue