diff options
-rw-r--r-- | COPYING | 10 | ||||
-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | README.md | 69 | ||||
-rwxr-xr-x | shite | 90 |
4 files changed, 192 insertions, 0 deletions
diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..f52335b --- /dev/null +++ b/COPYING | |||
@@ -0,0 +1,10 @@ | |||
1 | SHITE v.💩 | ||
2 | Copyright (C) 2022 C. Duckworth <acdw@acdw.net> | ||
3 | |||
4 | Everyone is permitted to do whatever with this software, without | ||
5 | limitation. This software comes without any warranty whatsoever, | ||
6 | but with two pieces of advice: | ||
7 | |||
8 | - Don't hurt yourself. | ||
9 | - Make good choices. | ||
10 | |||
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fe6ac4b --- /dev/null +++ b/Makefile | |||
@@ -0,0 +1,23 @@ | |||
1 | # SHITE | ||
2 | # by C. Duckworth <acdw@acdw.net> | ||
3 | |||
4 | PREFIX=/usr/local | ||
5 | NAME=shite | ||
6 | |||
7 | SCRIPT=$(PWD)/$(NAME) | ||
8 | |||
9 | help: | ||
10 | @echo "SHITE: by C. Duckworth" | ||
11 | @echo "Makefile targets:" | ||
12 | @echo "install: install to $(DESTDIR)$(PREFIX)." | ||
13 | @echo "link: symlink to $(DESTDIR)$(PREFIX)." | ||
14 | @echo "uninstall: remove from $(DESTDIR)$(PREFIX)" | ||
15 | |||
16 | install: $(SCRIPT) | ||
17 | install -D $< $(DESTDIR)$(PREFIX)/bin/$(NAME) | ||
18 | |||
19 | link: $(SCRIPT) | ||
20 | ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(NAME) | ||
21 | |||
22 | uninstall: | ||
23 | -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 @@ | |||
1 | # shite | ||
2 | ## what it says on the tin | ||
3 | |||
4 | `shite` shits out a site using posix `sh`, `awk`, and `cp`---that's it. | ||
5 | Of course, it is shite. But it'll make a site. | ||
6 | |||
7 | ## use | ||
8 | |||
9 | make a site directory somewhere on your system and fill it with HTML files. | ||
10 | these can be just the body parts of these files---they will be enclosed with a | ||
11 | template, which is discussed below. you can also ignore enclosing paragraphs | ||
12 | with `<p>` tags---paragraphs not starting with `<` will automatically be | ||
13 | enclosed with them. | ||
14 | |||
15 | when you run `shite`, it will collect all HTML files, run them through various | ||
16 | templates, and shit them out into the `out/` directory in the site directory. | ||
17 | each page will be sent through `.template.html` and into `out/PAGE/index.html`, | ||
18 | where `PAGE` is the filename without `.html`. Then they'll be collected into an | ||
19 | index using `.index.html`, and into an RSS 2.0 feed using `.feed.xml`. | ||
20 | |||
21 | `.template.html`, `index.html`, and `.feed.xml` are treated as sh `heredocs`. | ||
22 | that is, any `$variable`, `$(function)`, or the like will be expanded. `title`, | ||
23 | `body`, and `pubdate` are provided for convenience; you can define others in | ||
24 | `.shite.sh`. a very simple template could look like this: | ||
25 | |||
26 | ``` | ||
27 | <!DOCTYPE html> | ||
28 | <title>$(title)</title> | ||
29 | $(body) | ||
30 | ``` | ||
31 | |||
32 | every other file in the site directory---that is, any file or directory that | ||
33 | isn't an HTML or XML file---will be copied to `out/` recursively, so go nuts! | ||
34 | |||
35 | ### installation | ||
36 | |||
37 | ``` | ||
38 | # make install | ||
39 | ``` | ||
40 | |||
41 | ### invocation | ||
42 | |||
43 | invoking `shite` is simple: | ||
44 | |||
45 | ``` | ||
46 | $ shite [-d DOMAIN] [-C DIRECTORY] | ||
47 | ``` | ||
48 | |||
49 | `DOMAIN` is your site's domain for the feed generator; the default is | ||
50 | the name of the site directory. `DIRECTORY` will change the directory before | ||
51 | generating a site, so you can run `shite` from anywhere. | ||
52 | |||
53 | ## license | ||
54 | |||
55 | Copyright (C) 2022 c. Duckworth and licensed under the Good Choices License. | ||
56 | See COPYING for details. | ||
57 | |||
58 | ## contributing | ||
59 | |||
60 | Send me an [email](mailto:shite+git@me.acdw) with comments, complaints, and | ||
61 | merge requests. if you want. | ||
62 | |||
63 | ## testimonials | ||
64 | |||
65 | > oh dang that is fancy | ||
66 | ~ m455 | ||
67 | |||
68 | > hehe, nah it's shite | ||
69 | ~ acdw | ||
diff --git a/shite b/shite new file mode 100755 index 0000000..ebd9e1e --- /dev/null +++ b/shite | |||
@@ -0,0 +1,90 @@ | |||
1 | #!/bin/sh | ||
2 | # shite --- shit out a site | ||
3 | # by C. Duckworth <acdw@acdw.net> | ||
4 | |||
5 | expand() { | ||
6 | end="expand_$(date +%s)_${count:=0}" | ||
7 | eval "$( | ||
8 | echo "cat <<$end" | ||
9 | cat "$@" | ||
10 | echo | ||
11 | echo "$end" | ||
12 | )" && count=$((count + 1)) | ||
13 | } | ||
14 | |||
15 | body() { | ||
16 | awk 'NR==1{next;}{print;}' | ||
17 | } | ||
18 | |||
19 | phtml() { | ||
20 | awk 'BEGIN{RS="";}/^[ \t]*</{print;next;}{print "<p>"$0"</p>";}' | ||
21 | } | ||
22 | |||
23 | title() { | ||
24 | awk 'BEGIN{FS=" ";}NR==1{print $1;quit;}' | ||
25 | } | ||
26 | |||
27 | pubdate() { | ||
28 | awk 'BEGIN{FS=" ";}NR==1{print $2;quit;}' | ||
29 | } | ||
30 | |||
31 | filters() { | ||
32 | body | phtml | ||
33 | } | ||
34 | |||
35 | pages() { | ||
36 | for file; do | ||
37 | echo >&2 "$file" | ||
38 | filters <"$file" | | ||
39 | expand .template.html >out/"${1%.html}"/index.html | ||
40 | done | ||
41 | } | ||
42 | |||
43 | index() { | ||
44 | for file; do | ||
45 | echo >&2 "index: $file" | ||
46 | echo "<li><a href=\"$file\">$(title "$file")</a></li>" | ||
47 | done | expand .index.html >out/index.html | ||
48 | } | ||
49 | |||
50 | feed() { | ||
51 | for file; do | ||
52 | echo >&2 "feed: $file" | ||
53 | echo "<item>" | ||
54 | echo " <title>$(title "$file")</title>" | ||
55 | echo " <link>$DOMAIN/${file%.html}/</link>" | ||
56 | echo " <guid>$DOMAIN/${file%.html}/</guid>" | ||
57 | if test -n "$(pubdate "$file")"; then | ||
58 | echo " <pubDate>$(pubdate "$file")</pubDate>" | ||
59 | fi | ||
60 | echo "</item>" | ||
61 | done | expand .feed.xml >out/feed.xml | ||
62 | } | ||
63 | |||
64 | main() { | ||
65 | DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}" | ||
66 | SOURCE="$PWD" | ||
67 | while getopts d:C: opt; do | ||
68 | case "$opt" in | ||
69 | d) DOMAIN="$OPTARG" ;; | ||
70 | C) SOURCE="$OPTARG" ;; | ||
71 | *) exit 1 ;; | ||
72 | esac | ||
73 | done | ||
74 | shift "$((OPTIND - 1))" | ||
75 | |||
76 | cd "$SOURCE" | ||
77 | mkdir -p out | ||
78 | test -f .shite.sh && . .shite.sh | ||
79 | pages *.html | ||
80 | index *.html | ||
81 | feed *.html | ||
82 | for file in *; do | ||
83 | test "${file#*.}" = html && continue | ||
84 | test "${file#*.}" = xml && continue | ||
85 | cp -r "$file" out/ | ||
86 | done | ||
87 | } | ||
88 | |||
89 | test -n "$DEBUG" && set -x | ||
90 | test -n "$SOURCE" || main "$@" | ||