commit 885ed0981dcd92e526674802d7c997bbdaf00fa6
parent faa1a6b9a886e575845f1404749193746487bb49
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Sat, 20 Aug 2022 19:07:52 -0400
Translate image links into Markdown image links
If a gemini link points to a .jpeg, .jpg, or .png file, translate that
link into a Markdown-style image link (i.e. a link with a ! preceding
it) so that it will be compiled into an <img> tag for better viewing in
web browsers.
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/sbs b/sbs
@@ -173,14 +173,18 @@ build()
# in .gmi to .html (e.g. /blog/post1.gmi --> /blog/post1.html).
# The second sed expression converts all gemini-style links to
# markdown-style links.
- # The third sed expression fixes gemini links that only had a
- # URL so that the URL will be displayed as the link text in HTML
+ # The third sed expression fixes gemini links that only have a
+ # URL so that the URL will be displayed as the link text.
+ # The fourth sed expression converts links to images into
+ # Markdown's image syntax, so images will be displayed with the
+ # <img> tag.
if [ "$(echo "$file" | awk -F\. '{print $NF}' )" = "gmi" ]; then
printf "Converting: content%s/%s to markdown...\n" "$subDir" "$fileName"
fileName=$(basename "$file" .gmi)
sed -e 's/\(=>[ ]*\)\(.*\)\(.gmi\)\(.*\)/\1\2.html\4/g' \
-e 's/=>[ ]*\([^ ]*\)\( \|\)\(.*\)/[\3](\1)\n/g' \
-e 's/\[\](\(.*\))/[\1](\1)/g' \
+ -e 's/\(\[.*\]\)\((\(.*.jpe\?g\|.*.png\))\)/!\1\2/g' \
"$file" > /tmp/sbs/"$fileName".md
title=$(grep '^# ' "$file" | head -n1 | cut -d' ' -f2-)
description="Page auto-converted from the Gemini format."