commit ffbd95acd986489ab187c81f369e2056c71298c0 parent fba8da8d119d4b8bb61eefd031a5e8f37e31ba8a Author: Jake Bauer <jbauer@paritybit.ca> Date: Wed, 17 Aug 2022 18:30:45 -0400 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. Diffstat:
M | sbs | | | 35 | +++++++++++++++++++++++++++++------ |
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/sbs b/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