Improve build command with Gemini support
sbs can now convert gemtext to markdown which allows mixing gemini and markdown in the same site directory and easy publishing of gemini content for the web. A modification of the build command was also added to allow building the entire site without specifying any paths.
This commit is contained in:
parent
fba8da8d11
commit
ffbd95acd9
35
sbs
35
sbs
|
@ -139,7 +139,7 @@ build()
|
|||
{
|
||||
for file in "$@"; do
|
||||
if [ -d "$file" ]; then
|
||||
"$0" build "$file"/*
|
||||
build "$file"/*
|
||||
continue
|
||||
elif [ ! -f "$file" ]; then
|
||||
printf "ERROR: %s does not exist.\n" "$file"
|
||||
|
@ -150,18 +150,34 @@ build()
|
|||
subDir=$(dirname "$file" | sed "s/^content//")
|
||||
mkdir -p "static/$subDir"
|
||||
|
||||
# Convert Gemtext files to Markdown
|
||||
# The first sed expression converts all local links that end
|
||||
# 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.
|
||||
if [ "$(echo "$file" | awk -F\. '{print $NF}' )" = "gmi" ]; then
|
||||
printf "Converting: %s to markdown...\n" "$file"
|
||||
fileName=$(basename "$file" .gmi)
|
||||
sed -e 's/\(=> \/\)\(.*\)\(.gmi\)\(.*\)/\1\2.html\4/g' \
|
||||
-e 's/=> \([^ ]*\) \(.*\)/[\2](\1)\n/g' \
|
||||
"$file" > /tmp/sbs/"$fileName".md
|
||||
title=$(grep '^# ' "$file" | head -n1 | cut -d' ' -f2-)
|
||||
description="Page auto-converted from the Gemini format."
|
||||
file=/tmp/sbs/"$fileName".md
|
||||
fi
|
||||
|
||||
printf "Creating: static%s/%s.html...\n" "$subDir" "$fileName"
|
||||
|
||||
# Extract metadata from the markdown document
|
||||
title=$(lowdown -X title "$file")
|
||||
meta=$(lowdown -X summary "$file")
|
||||
# Extract metadata from markdown doc (if not converted from gmi)
|
||||
title=${title:-$(lowdown -X title "$file")}
|
||||
description=${description:-$(lowdown -X summary "$file")}
|
||||
|
||||
# Build and process the output document
|
||||
lowdown $buildOptions "$file" \
|
||||
| cat "templates/header.html" - "templates/footer.html" \
|
||||
| sed -e "s/<title><\/title>/<title>$title - $siteName<\/title>/" \
|
||||
-e "s/lang=\"\"/lang=\"$languageCode\"/" \
|
||||
-e "s/content=\"\"/content=\"$meta\"/" \
|
||||
-e "s/content=\"\"/content=\"$description\"/" \
|
||||
> "static/$subDir/$fileName".html
|
||||
|
||||
printf "Created: static%s/%s.html\n" "$subDir" "$fileName"
|
||||
|
@ -179,7 +195,14 @@ case "$1" in
|
|||
"build")
|
||||
shift
|
||||
parse_configuration
|
||||
build "$@"
|
||||
mkdir -p /tmp/sbs/
|
||||
# Allows simply running "sbs build" without path(s)
|
||||
if [ $# -eq 0 ]; then
|
||||
build ./content/*
|
||||
else
|
||||
build "$@"
|
||||
fi
|
||||
rm -rf /tmp/sbs/
|
||||
;;
|
||||
"genfeed")
|
||||
parse_configuration
|
||||
|
|
Loading…
Reference in New Issue