sbs

A Simple Blogging System.
git clone https://git.sr.ht/~jbauer/sbs
Log | Files | Refs | README | LICENSE

commit eda3c159ea711a5a2d3ee9969de507fdc320c149
parent e0db2ae481844e722c69e68f34ad1889cb3bd2b9
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Sun, 13 Feb 2022 20:47:59 -0500

Implement basic website generation functionality

Diffstat:
MREADME.md | 21+++++++++++++++++++--
Aconfig.ini.example | 3+++
Asbs | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -1,7 +1,24 @@ # Simple Blogging System (working title) -A blogging system designed to be simpler to use than existing solutions such as -Hugo and Jekyll. +A simple static site generator designed to be simpler to use than existing +solutions such as Hugo and Jekyll. + +# Usage + +1. Create the directories `content/ static/ templates/` in your website's + directory. +2. Rename `config.ini.example` to `config.ini` and change it to fit your + website. The default buildOptions translates markdown into HTML and doesn't + ignore HTML tags embedded in the markdown. +3. Create and alter `templates/header.html` and `templates/footer.html`. These + are the header and footer which will surround the content of each page on + your website. +4. Make your pages under the `content/` directory. sbs supports MultiMarkdown + Metadata, see the example pages for an example. +5. Run `sbs <files>` to build particular files. The output will appear in + `static/`. +6. Use a utility like `rsync` to copy the contents of the `static/` directory to + your webserver. ## Goals diff --git a/config.ini.example b/config.ini.example @@ -0,0 +1,3 @@ +siteName = "example.com" +languageCode = "en" +buildOptions = "-Thtml --html-no-skiphtml --html-no-escapehtml" diff --git a/sbs b/sbs @@ -0,0 +1,62 @@ +#!/bin/sh + +# sbs +# A simple and straightforward static site generator +# Copyright (C) 2022 Jake Bauer +# See the README for usage instructions and LICENSE for license terms. + +# TODO: Image optimization not using third party service? +# TODO: CSS minification without using third party service? +# TODO: Live server that watches for page updates? +# TODO: "New" site which creates necessary dirs and files in a directory + +set -o errexit +set -o nounset + +# Check that all the required programs are installed +if [ ! -x "$(command -v lowdown)" ]; then + echo "The program 'lowdown' is needed but was not found." + exit 1 +fi + +options="buildOptions siteName languageCode" +for key in $options; do + value=$(grep "$key" config.ini | cut -d'=' -f2 | xargs) + if [ -n "$value" ]; then + eval "$key='$value'" + else + echo "Error: $key not configured in config file." + exit 1 + fi +done + +for file in "$@"; do + if [ ! -f "$file" ]; then + printf "ERROR: %s not found or is not a file.\n" "$file" + continue + fi + + fileName=$(basename "$file" .md) + subDir=$(dirname "$file" | sed "s/^content//") + mkdir -p "static/$subDir" + + # Extract metadata from the markdown document + author=$(lowdown -X author "$file") + title=$(lowdown -X title "$file") + date=$(lowdown -X date "$file") + css=$(lowdown -X css "$file") + meta=$(lowdown -X summary "$file") + + # Build and process the output document + # TODO: author and date insertion + # TODO: css file addition + lowdown $buildOptions "$file" \ + | cat "templates/header.html" - "templates/footer.html" \ + | sed "s/<title>.*<\/title>/<title>$title - $siteName<\/title>/" \ + | sed "s/content=\"\"/content=\"$meta\"/" \ + > "static/$subDir/$fileName".html + + printf "Created: static/$subDir$fileName.html\n" +done + +exit 0