paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit ec2729f7aef5eec29d4dfe318cc752b1eaba907e
parent 533a07c35432f5187a2a30221530c9230ea90217
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Thu, 21 May 2020 01:41:43 -0400

Begin rewrite of compile script

So far, it supports CSS, auto-uploading files, better configuration of
directories/other options, more extensible interface for handling new
filetypes if needed in the future.

Still need to write the functions which compile the MD -> HTML documents
as this is the most complicated. Pandoc will be used instead of markdown
but I need to make the other bits (e.g. title, toc, etc) cleaner.

Diffstat:
Acompile-new | 155+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 155 insertions(+), 0 deletions(-)

diff --git a/compile-new b/compile-new @@ -0,0 +1,155 @@ +#!/bin/sh + +# compile +# A POSIX shell script to build pages and minify css for paritybit.ca. +# 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 + +# Set to "false" to disable auto-upload +autoUpload="false" +# Where md files are +pageDir="pages/" +# Where compiled md -> html pages will go +htmlDir="public/html" +mkdir -p "$htmlDir" +# Where minified css will go +cssDir="public/css" +mkdir -p "$cssDir" +# Where intermediate build files will go +buildDir="build/" +mkdir -p "$buildDir" + +# Prints the message passed as the 1st argument in bold red. +print_error_msg() +{ + tput sgr0; tput setaf 1; tput bold + printf "%s\n" "$1" + tput sgr0 +} + +# Prints "DONE" in bold green. +print_success_msg() +{ + tput sgr0; tput setaf 2; tput bold + echo "DONE\n" + tput sgr0 +} + +# Prints the message passed as the 1st argument in bold yellow. +print_info_msg() +{ + tput sgr0; tput setaf 3; tput bold + printf "%s\n" "$1" + tput sgr0 +} + +# Expects ~/.ssh/config to contain an entry for "paritybit.ca" +auto_upload() +{ + if [ "$autoUpload" != "true" ]; then + return 0 + fi + print_info_msg "Auto-uploading file..." + if [ "$autoUpload" = "true" ]; then + if [ "$fileExt" = "css" ]; then + cd public && rsync -rR css/"$fileName".min.css \ + paritybit.ca:uploads/ && cd .. + elif [ "$fileExt" = "md" ]; then + cd public && rsync -rR html/"$savePath""$fileName".html \ + paritybit.ca:uploads/ && cd .. + fi + fi +} + +compile_css() +{ + echo "MINIFYING CSS: $fileName" + curl --data "input=$(cat "$file")" https://cssminifier.com/raw \ + > "$cssDir"/"$fileName".min.css + if [ $? != 0 ]; then + print_error_msg "There was an issue minifying this CSS." + exit 1 + fi +} + +compile_md() +{ + true +} + +set_html_title() +{ + true +} + +set_html_meta() +{ + true +} + +set_html_csslink() +{ + true +} + +set_html_toc() +{ + true +} + +for file in "$@"; do + if [ ! -f "$file" ]; then + print_error_msg "ERROR: $file not found or is not a file." + continue + fi + + fileName=$(basename "$file" | cut -d'.' -f1) + fileExt=$(echo "$file" | awk -F . '{if (NF>1) {print $NF}}') + fileDir=$(dirname "$file") + echo "$fileName" + echo "$fileExt" + echo "$fileDir" + + if [ "$fileExt" = "css" ]; then + compile_css + auto_upload + elif [ "$fileExt" = "md" ]; then + compile_md + set_html_title + set_html_meta + set_html_csslink + set_html_toc + auto_upload + fi + + print_success_msg +done