From fb6a1c2f1cbeedeb9a2b1851dfc2cee5e0513a39 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Fri, 8 Apr 2022 17:39:59 +0530 Subject: [PATCH] feat: init --- .gitignore | 2 + Makefile | 14 ++++++ config.toml | 16 ++++++ scripts/lib.sh | 32 ++++++++++++ scripts/spellcheck.sh | 95 ++++++++++++++++++++++++++++++++++++ scripts/zola.sh | 110 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 269 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 config.toml create mode 100755 scripts/lib.sh create mode 100755 scripts/spellcheck.sh create mode 100755 scripts/zola.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0320acb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +public/ +bin/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c57bf54 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +default: ## Build the website + ./scripts/zola.sh build + +clean: ## Clean build assets + ./scripts/zola.sh clean + +env: ## Download build dependencies and setup dev environement + ./scripts/zola.sh install + +help: ## Prints help for targets with comments + @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +serve: ## Serve website during development + ./scripts/zola.sh zola -- serve diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..b6e4a7c --- /dev/null +++ b/config.toml @@ -0,0 +1,16 @@ +# The URL the site will be built for +base_url = "https://hostea.org" + +# Whether to automatically compile all Sass files in the sass directory +compile_sass = true + +# Whether to build a search index to be used later on by a JavaScript library +build_search_index = true + +[markdown] +# Whether to do syntax highlighting +# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola +highlight_code = true + +[extra] +# Put all your custom variables here diff --git a/scripts/lib.sh b/scripts/lib.sh new file mode 100755 index 0000000..da0b409 --- /dev/null +++ b/scripts/lib.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Copyright © 2021 Aravinth Manivannan +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +check_arg(){ + if [ -z $1 ] + then + help + exit 1 + fi +} + +match_arg() { + if [ $1 == $2 ] || [ $1 == $3 ] + then + return 0 + else + return 1 + fi +} diff --git a/scripts/spellcheck.sh b/scripts/spellcheck.sh new file mode 100755 index 0000000..6be8a7a --- /dev/null +++ b/scripts/spellcheck.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# Used in CI workflow: install and check for spelling errors +# Copyright © 2021 Aravinth Manivannan +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +readonly MISSPELL_DOWNLOAD="https://github.com/client9/misspell/releases/download/v0.3.4/misspell_0.3.4_linux_64bit.tar.gz" +readonly TMP_DIR=$(pwd)/tmp +readonly PROJECT_ROOT=$(pwd) +readonly MISSPELL_TARBALL="$TMP_DIR/misspell.tar.bz2" +readonly MISSPELL="$TMP_DIR/misspell" + +set -Eeuo pipefail + +source $(pwd)/scripts/lib.sh + +FLAGS="" + +help() { + cat << EOF +spellcheck.sh: Check for spelling errors +USAGE: + spellcheck.sh +OPTIONS: + c --check check for spelling erros + h --help print this help menu + w --write check and fix spelling errors +EOF +} + + + +download() { + if [ ! -e $MISSPELL ]; + then + echo "[*] Downloading misspell" + wget --quiet --output-doc=$MISSPELL_TARBALL $MISSPELL_DOWNLOAD; + cd $TMP_DIR + tar -xf $MISSPELL_TARBALL; + cd $PROJECT_ROOT + fi +} + +spell_check_codespell() { + _check(){ + codespell $FLAGS --ignore-words-list=$1 $PROJECT_ROOT/$2 || true + } + _check README.md + _check contents +} + +spell_check_misspell() { + mkdir $TMP_DIR || true + download + + _check(){ + $MISSPELL $FLAGS -i $1 $PROJECT_ROOT/$2 + } + + _check contents + _check README.md +} + +check_arg $1 + +if match_arg $1 'w' '--write' +then + echo "[*] checking and correcting spellings" + FLAGS="-w" + spell_check_misspell + spell_check_codespell +elif match_arg $1 'c' '--check' +then + echo "[*] checking spellings" + spell_check_misspell + spell_check_codespell +elif match_arg $1 'h' '--help' +then + help +else + echo "undefined option" + help + exit 1 +fi diff --git a/scripts/zola.sh b/scripts/zola.sh new file mode 100755 index 0000000..0ac0274 --- /dev/null +++ b/scripts/zola.sh @@ -0,0 +1,110 @@ +#!/bin/bash +# Used in CI workflow: install Zola binary from GitHub +# Copyright © 2021 Aravinth Manivannan +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +set -euo pipefail + +readonly TARBALL=zola.tar.gz +readonly SOURCE="https://github.com/getzola/zola/releases/download/v0.15.3/zola-v0.15.3-x86_64-unknown-linux-gnu.tar.gz" + +readonly BIN_PATH=bin +readonly BIN=$BIN_PATH/zola + +readonly DIST=public + +source $(pwd)/scripts/lib.sh + +help() { + cat << EOF +zola.sh: Zola build script +USAGE: + zola.sh +OPTIONS: + b build build website + c clean clean dependencies and build artifacts + h help print this help menu + i install install build dependencies + u url make urls relative + z zola invoke zola +EOF +} + +download() { + echo "Downloading Zola" + wget --quiet --output-document=$TARBALL $SOURCE + tar -xvzf $TARBALL > /dev/null + rm $TARBALL + echo "Downloaded zola into $BIN" +} + +init() { + if [ ! -d $BIN_PATH ] + then + mkdir $BIN_PATH + fi + + if [ ! -f $BIN ] + then + cd $BIN_PATH + download + fi +} + +run() { + $BIN "${@:1}" +} + +build() { + run build +} + +no_absolute_url() { + sed -i 's/https:\/\/hostea.org//g' $(find public -type f | grep html) +} + +clean() { + rm -rf $BIN_PATH || true + rm -rf $DIST || true + echo "Workspace cleaned" +} + +check_arg $1 + +if match_arg $1 'i' 'install' +then + init +elif match_arg $1 'c' 'clean' +then + clean +elif match_arg $1 'b' 'build' +then + build +elif match_arg $1 'h' 'help' +then + help +elif match_arg $1 'u' 'url' +then + no_absolute_url +elif match_arg $1 'z' 'zola' +then + $BIN "${@:3}" +else + echo "Error: $1 is not an option" + help + exit 1 +fi + +exit 0