commit 13b2b8765c05497054f5f7c27f574d5319d8aac4
parent fc5fee5ba3544966a8d1c93adae2dbc0b912bc6a
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Sun, 27 Sep 2020 13:35:36 -0400
Create compile script for Gemini
Diffstat:
6 files changed, 232 insertions(+), 28 deletions(-)
diff --git a/gemini/compile b/gemini/compile
@@ -0,0 +1,154 @@
+#!/bin/sh
+
+# compile
+# A POSIX shell script to build pages for a geminispace.
+# NOTE: See the README for the expected format of md files.
+#
+# Copyright (C) 2020 Jake Bauer
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# POSIX Shell "Strict Mode"
+set -o errexit
+set -o nounset
+IFS=$(printf '\n\t')
+
+# Check that all the required programs are installed
+if [ ! -x "$(command -v rsync)" ]; then
+ echo "The program 'rsync' is needed but was not found."
+ exit 1
+fi
+if [ ! -x "$(command -v curl)" ]; then
+ echo "The program 'curl' is needed but was not found."
+ exit 1
+fi
+
+# Define colours
+CLEAR="\033[0m"
+RED="\033[0;31m"
+GREEN="\033[0;32m"
+YELLOW="\033[0;33m"
+
+### CONFIGURATION ###
+# The geminispace domain
+siteName="paritybit.ca"
+# Set to "false" to disable auto-upload
+autoUpload="true"
+# Where to upload files
+remote="paritybit.ca:/srv/gemini/"
+# Where the header/footer files are
+templateDir="template/"
+# Where gmi files are
+pageDir="pages/"
+# Where compiled gmi pages will go
+gmiDir="public/gmi"
+mkdir -p "$gmiDir"
+
+# Prints the message passed as the 1st argument in red.
+print_error_msg()
+{
+ printf "$RED[ee] %s\n$CLEAR" "$1"
+}
+
+# Prints the message passed as the 1st argument in green.
+print_success_msg()
+{
+ printf "$GREEN[ok] %s\n$CLEAR" "$1"
+}
+
+# Prints the message passed as the 1st argument in yellow.
+print_header_msg()
+{
+ printf "$YELLOW[hh] %s\n$CLEAR" "$1"
+}
+
+# Prints the message passed as the 1st argument with default colours.
+print_info_msg()
+{
+ printf "$CLEAR[ii] %s\n" "$1"
+}
+
+auto_upload()
+{
+ if [ "$autoUpload" != "true" ]; then
+ return 0
+ fi
+ print_info_msg "Auto-uploading file"
+ if [ "$autoUpload" = "true" ]; then
+ outputFile="$(echo "$outputFile" | cut -d'/' -f2-)"
+ cd public/gmi && rsync -rR "$outputFile" "$remote" && cd ..
+ fi
+}
+
+compile_gmi()
+{
+ print_header_msg "COMPILING GEMINI: $file"
+ mkdir -p "$gmiDir"/"$subDir"
+
+ cat "$templateDir"/header.gmi "$file" "$templateDir"/footer.gmi \
+ > "$gmiDir"/"$subDir"/"$fileName".gmi
+
+ outputFile="$subDir/$fileName.gmi"
+}
+
+# Read and parse command line flags
+while test $# -gt 0; do
+ case "$1" in
+ -h|--help)
+ echo "compile - generate static gemini pages"
+ echo ""
+ echo "usage: compile [options] files"
+ echo ""
+ echo "options:"
+ echo "-h|--help show brief help"
+ echo "-a|--auto-upload auto-upload generated files"
+ echo "-n|--no-auto-upload do not auto-upload the generated files"
+ exit 0
+ ;;
+ -n|--no-auto-upload)
+ autoUpload="false"
+ shift
+ ;;
+ -a|--auto-upload)
+ autoUpload="true"
+ shift
+ ;;
+ --|*)
+ break
+ ;;
+ esac
+done
+
+for file in "$@"; do
+ if [ ! -f "$file" ]; then
+ print_error_msg "ERROR: $file not found or is not a file."
+ continue
+ fi
+
+ # First run of fileName needed because if the for loop operates on $file,
+ # the extension will not be properly pruned
+ fileName=$(basename -s .gmi "$file")
+ fileExt=$(echo "$file" | awk -F . '{if (NF>1) {print $NF}}')
+ fileDir=$(dirname "$file")
+ subDir=$(echo "$fileDir" | sed "s/^pages//")
+
+ if [ "$fileExt" = "gmi" ]; then
+ compile_gmi
+ auto_upload
+ else
+ print_error_msg "ERROR: nothing to do."
+ fi
+
+ print_success_msg "FINISHED: gemini://$siteName/$subDir/$fileName.gmi"
+done
diff --git a/gemini/home.gmi b/gemini/home.gmi
@@ -1,28 +0,0 @@
-```
- _ _ _ _ _
- _ __ __ _ _ __(_) |_ _ _| |__ (_) |_ ___ __ _
- | '_ \ / _` | '__| | __| | | | '_ \| | __| / __/ _` |
- | |_) | (_| | | | | |_| |_| | |_) | | |_ | (_| (_| |
- | .__/ \__,_|_| |_|\__|\__, |_.__/|_|\__(_)___\__,_|
- |_| |___/
-
-```
-
-# Jake Bauer's Personal Geminispace
-
-This is the geminispace belonging to Jake Bauer <jbauer@paritybit.ca>, student of computer science and small internet enthusiast. Here are some other places I exist on the internet:
-
-=> https://www.paritybit.ca My Website and Blog
-=> https://git.paritybit.ca My Git Server
-=> https://ftp.paritybit.ca My File Sharing Server
-=> https://pleroma.paritybit.ca Me on the Fediverse
-=> https://git.sr.ht/~jbauer My Sourcehut Profile
-
-## Blog posts
-
-[A list of blog posts will appear here as they are added to the site]
-
-```
------------------
-```
-All content on this site is licensed under the CC BY-SA 4.0 International License.
diff --git a/gemini/pages/home.gmi b/gemini/pages/home.gmi
@@ -0,0 +1,14 @@
+# Jake Bauer's Personal Geminispace
+
+This is the geminispace belonging to Jake Bauer <jbauer@paritybit.ca>, student of computer science and small internet enthusiast. Here are some other places I exist on the internet:
+
+=> https://www.paritybit.ca My Website and Blog
+=> https://git.paritybit.ca My Git Server
+=> https://ftp.paritybit.ca My File Sharing Server
+=> https://pleroma.paritybit.ca Me on the Fediverse
+=> https://git.sr.ht/~jbauer My Sourcehut Profile
+
+## Blog posts
+
+[A list of blog posts will appear here as they are added to the site]
+
diff --git a/gemini/public/gmi/home.gmi b/gemini/public/gmi/home.gmi
@@ -0,0 +1,39 @@
+```
+ _ _ _ _ _
+ _ __ __ _ _ __(_) |_ _ _| |__ (_) |_ ___ __ _
+ | '_ \ / _` | '__| | __| | | | '_ \| | __| / __/ _` |
+ | |_) | (_| | | | | |_| |_| | |_) | | |_ | (_| (_| |
+ | .__/ \__,_|_| |_|\__|\__, |_.__/|_|\__(_)___\__,_|
+ |_| |___/
+
+```
+
+THIS GEMINISPACE IS STILL UNDER CONSTRUCTION (construction.gif)
+
+=> gemini://paritybit.ca/ Home
+=> gemini://paritybit.ca/blog Blog
+=> gemini://paritybit.ca/links Links
+=> gemini://paritybit.ca/projects Projects
+=> gemini://paritybit.ca/about About Me
+=> gemini://paritybit.ca/uses Uses
+=> gemini://paritybit.ca/now Now
+=> gemini://paritybit.ca/contact Contact
+
+# Jake Bauer's Personal Geminispace
+
+This is the geminispace belonging to Jake Bauer <jbauer@paritybit.ca>, student of computer science and small internet enthusiast. Here are some other places I exist on the internet:
+
+=> https://www.paritybit.ca My Website and Blog
+=> https://git.paritybit.ca My Git Server
+=> https://ftp.paritybit.ca My File Sharing Server
+=> https://pleroma.paritybit.ca Me on the Fediverse
+=> https://git.sr.ht/~jbauer My Sourcehut Profile
+
+## Blog posts
+
+[A list of blog posts will appear here as they are added to the site]
+
+```
+-----------------
+```
+All content on this site is licensed under the CC BY-SA 4.0 International License.
diff --git a/gemini/template/footer.gmi b/gemini/template/footer.gmi
@@ -0,0 +1,4 @@
+```
+-----------------
+```
+All content on this site is licensed under the CC BY-SA 4.0 International License.
diff --git a/gemini/template/header.gmi b/gemini/template/header.gmi
@@ -0,0 +1,21 @@
+```
+ _ _ _ _ _
+ _ __ __ _ _ __(_) |_ _ _| |__ (_) |_ ___ __ _
+ | '_ \ / _` | '__| | __| | | | '_ \| | __| / __/ _` |
+ | |_) | (_| | | | | |_| |_| | |_) | | |_ | (_| (_| |
+ | .__/ \__,_|_| |_|\__|\__, |_.__/|_|\__(_)___\__,_|
+ |_| |___/
+
+```
+
+THIS GEMINISPACE IS STILL UNDER CONSTRUCTION (construction.gif)
+
+=> gemini://paritybit.ca/ Home
+=> gemini://paritybit.ca/blog Blog
+=> gemini://paritybit.ca/links Links
+=> gemini://paritybit.ca/projects Projects
+=> gemini://paritybit.ca/about About Me
+=> gemini://paritybit.ca/uses Uses
+=> gemini://paritybit.ca/now Now
+=> gemini://paritybit.ca/contact Contact
+