From 0da76871ae527c6d97717c3f8359763ebe9bd329 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 16 Sep 2022 14:55:51 -0500 Subject: Initial commit --- COPYING | 10 +++++++ Makefile | 23 ++++++++++++++++ README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ shite | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 COPYING create mode 100644 Makefile create mode 100644 README.md create mode 100755 shite diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..f52335b --- /dev/null +++ b/COPYING @@ -0,0 +1,10 @@ +SHITE v.💩 +Copyright (C) 2022 C. Duckworth + +Everyone is permitted to do whatever with this software, without +limitation. This software comes without any warranty whatsoever, +but with two pieces of advice: + +- Don't hurt yourself. +- Make good choices. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fe6ac4b --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# SHITE +# by C. Duckworth + +PREFIX=/usr/local +NAME=shite + +SCRIPT=$(PWD)/$(NAME) + +help: + @echo "SHITE: by C. Duckworth" + @echo "Makefile targets:" + @echo "install: install to $(DESTDIR)$(PREFIX)." + @echo "link: symlink to $(DESTDIR)$(PREFIX)." + @echo "uninstall: remove from $(DESTDIR)$(PREFIX)" + +install: $(SCRIPT) + install -D $< $(DESTDIR)$(PREFIX)/bin/$(NAME) + +link: $(SCRIPT) + ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(NAME) + +uninstall: + -rm -f $< $(DESTDIR)$(PREFIX)/bin/$(NAME) diff --git a/README.md b/README.md new file mode 100644 index 0000000..96b23ce --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# shite +## what it says on the tin + +`shite` shits out a site using posix `sh`, `awk`, and `cp`---that's it. +Of course, it is shite. But it'll make a site. + +## use + +make a site directory somewhere on your system and fill it with HTML files. +these can be just the body parts of these files---they will be enclosed with a +template, which is discussed below. you can also ignore enclosing paragraphs +with `

` tags---paragraphs not starting with `<` will automatically be +enclosed with them. + +when you run `shite`, it will collect all HTML files, run them through various +templates, and shit them out into the `out/` directory in the site directory. +each page will be sent through `.template.html` and into `out/PAGE/index.html`, +where `PAGE` is the filename without `.html`. Then they'll be collected into an +index using `.index.html`, and into an RSS 2.0 feed using `.feed.xml`. + +`.template.html`, `index.html`, and `.feed.xml` are treated as sh `heredocs`. +that is, any `$variable`, `$(function)`, or the like will be expanded. `title`, +`body`, and `pubdate` are provided for convenience; you can define others in +`.shite.sh`. a very simple template could look like this: + +``` + +$(title) +$(body) +``` + +every other file in the site directory---that is, any file or directory that +isn't an HTML or XML file---will be copied to `out/` recursively, so go nuts! + +### installation + +``` +# make install +``` + +### invocation + +invoking `shite` is simple: + +``` +$ shite [-d DOMAIN] [-C DIRECTORY] +``` + +`DOMAIN` is your site's domain for the feed generator; the default is +the name of the site directory. `DIRECTORY` will change the directory before +generating a site, so you can run `shite` from anywhere. + +## license + +Copyright (C) 2022 c. Duckworth and licensed under the Good Choices License. +See COPYING for details. + +## contributing + +Send me an [email](mailto:shite+git@me.acdw) with comments, complaints, and +merge requests. if you want. + +## testimonials + +> oh dang that is fancy +~ m455 + +> hehe, nah it's shite +~ acdw diff --git a/shite b/shite new file mode 100755 index 0000000..ebd9e1e --- /dev/null +++ b/shite @@ -0,0 +1,90 @@ +#!/bin/sh +# shite --- shit out a site +# by C. Duckworth + +expand() { + end="expand_$(date +%s)_${count:=0}" + eval "$( + echo "cat <<$end" + cat "$@" + echo + echo "$end" + )" && count=$((count + 1)) +} + +body() { + awk 'NR==1{next;}{print;}' +} + +phtml() { + awk 'BEGIN{RS="";}/^[ \t]*"$0"

";}' +} + +title() { + awk 'BEGIN{FS=" ";}NR==1{print $1;quit;}' +} + +pubdate() { + awk 'BEGIN{FS=" ";}NR==1{print $2;quit;}' +} + +filters() { + body | phtml +} + +pages() { + for file; do + echo >&2 "$file" + filters <"$file" | + expand .template.html >out/"${1%.html}"/index.html + done +} + +index() { + for file; do + echo >&2 "index: $file" + echo "
  • $(title "$file")
  • " + done | expand .index.html >out/index.html +} + +feed() { + for file; do + echo >&2 "feed: $file" + echo "" + echo " $(title "$file")" + echo " $DOMAIN/${file%.html}/" + echo " $DOMAIN/${file%.html}/" + if test -n "$(pubdate "$file")"; then + echo " $(pubdate "$file")" + fi + echo "" + done | expand .feed.xml >out/feed.xml +} + +main() { + DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}" + SOURCE="$PWD" + while getopts d:C: opt; do + case "$opt" in + d) DOMAIN="$OPTARG" ;; + C) SOURCE="$OPTARG" ;; + *) exit 1 ;; + esac + done + shift "$((OPTIND - 1))" + + cd "$SOURCE" + mkdir -p out + test -f .shite.sh && . .shite.sh + pages *.html + index *.html + feed *.html + for file in *; do + test "${file#*.}" = html && continue + test "${file#*.}" = xml && continue + cp -r "$file" out/ + done +} + +test -n "$DEBUG" && set -x +test -n "$SOURCE" || main "$@" -- cgit 1.4.1-21-gabe81