summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-03-11 23:00:20 -0500
committerCase Duckworth2024-03-11 23:00:20 -0500
commit05d812d91ec3a1d66f630afaf6a26eb0d4df12a7 (patch)
treea134f2112460cca9f00295d6fe0b71d9deab49de
downloadll-05d812d91ec3a1d66f630afaf6a26eb0d4df12a7.tar.gz
ll-05d812d91ec3a1d66f630afaf6a26eb0d4df12a7.zip
First commit
-rw-r--r--.gitignore3
-rwxr-xr-xll118
-rw-r--r--things-im-doing-instead-of-work.ul7
-rw-r--r--types-of-lists-ll-supports.dl13
4 files changed, 141 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c25374 --- /dev/null +++ b/.gitignore
@@ -0,0 +1,3 @@
1*.xml
2*.html
3index.al \ No newline at end of file
diff --git a/ll b/ll new file mode 100755 index 0000000..cd3fee2 --- /dev/null +++ b/ll
@@ -0,0 +1,118 @@
1#!/bin/sh
2
3# Config
4BASE_URL=.
5SITE_TITLE="a listlog"
6SITE_COPYRIGHT="Case Duckworth"
7BACK_LINK=index.html,back
8
9wrap() {
10 title="$(sed 1q "$1")"
11 cat <<HEAD
12<!DOCTYPE html>
13<title>$title</title>
14<style>
15body{max-width:48em;font:20px/1.4 serif;margin:auto;padding:1em;}
16footer{position:absolute;bottom:0;left:0;padding:1em;background:white;}
17dt{font-weight:bold;}
18</style>
19<body>
20<!-- LIST_START -->
21<h1>$title</h1>
22HEAD
23 cat
24 cat <<FOOT
25<!-- LIST_END -->
26<footer>
27$(test "$2" && printf '<a href="%s">%s</a>' "${2%%,*}" "${2##*,}")
28$(case "$1" in (*index*) printf '<a href="%s">%s</a>' \
29 "$BASE_URL/feed.xml" feed ;; esac)
30</footer>
31</body></html>
32FOOT
33}
34
35# Library
36list()(tag="$1";shift;echo "<$tag>"; sed 1d|awk "$@"; echo "</$tag>")
37# unordered list
38ul()(list ul '/^$/{next}{printf "<li>%s</li>\n",$0}')
39# ordered list
40ol()(list ol '/^$/{next}{printf "<li>%s</li>\n",$0}')
41# anchor (link) list
42al()(list ul -F"\n" -vRS= '{printf "<li><a href=\"%s\">%s</a></li>\n",$1,$2}')
43# definition list
44dl()(list dl -F"\n" -vRS= '{printf "<dt>%s</dt>\n<dd>%s</dd>\n",$1,$2}')
45
46rss() {
47 cat <<HEAD
48<?xml version="1.0" encoding="utf-8"?>
49<feed xmlns="http://www.w3.org/2005/Atom">
50<title>$(sed 1q index.al)</title>
51<link href="$BASE_URL/feed.xml" rel="self" />
52<link href="$BASE_URL" />
53<id>$BASE_URL</id>
54<rights>$SITE_COPYRIGHT</rights>
55<updated>$(date +%FT%TZ)</updated>
56HEAD
57 # entries
58 awk -F"\n" -vRS= \
59 -vbase="$BASE_URL" \
60 -vauthor="$SITE_COPYRIGHT" \
61 'NR==1{next}
62{ url=$1; title=$2;
63 file=url; sub(base "/", "", file)
64 printf "<entry>\n<id>%s</id>\n", url
65 printf "<link rel=\"alternate\" href=\"%s\" />\n", url
66 printf "<title>%s</title>\n", title
67 printf "<author><name>%s</name></author>\n", author
68 printf "<updated>%s</updated>\n", updated(file)
69 printf "<content type=\"html\"><![CDATA[%s]]></content>\n",
70 slurp(file)
71 printf "</entry>\n"
72}
73function updated (file) {
74 cmd = "stat -c %y " file " 2>/dev/null"
75 cmd = cmd " || stat -f %Sm -t %FT%TZ " file " 2>/dev/null"
76 cmd | getline upd
77 close(cmd)
78 return upd
79}
80function slurp (file, out, bodyp) {
81 oldRS=RS; RS="\n"
82 while ((getline < file) > 0) {
83 if ($0 ~ /LIST_END/) bodyp = 0
84 if (bodyp) out = out (out?"\n":"") $0
85 if ($0 ~ /LIST_START/) bodyp = 1
86 }
87 RS=oldRS
88 return out
89}'
90 cat <<FOOT
91</feed>
92FOOT
93}
94
95# Main
96main() {
97 printf "%s\n\n" "$SITE_TITLE" > index.al
98 ls -t *.ul *.dl *.ol *.al 2>/dev/null |
99 sed '/index.al/d' |
100 while read -r lst
101 do
102 printf >&2 "Processing %s..." "$lst"
103 "${lst##*.}" < "$lst" |
104 wrap "$lst" "$BACK_LINK" > "${lst%%.*}.html"
105 echo "$BASE_URL/${lst%%.*}.html" >> index.al
106 echo "$(sed 1q "$lst")" >> index.al
107 echo >> index.al
108 echo >&2 ok
109 done
110 printf >&2 "Processing index..."
111 al < index.al | wrap index.al > index.html &&
112 echo >&2 ok
113 printf >&2 "Processing rss..."
114 rss < index.al > feed.xml &&
115 echo >&2 ok
116}
117
118main "$@"
diff --git a/things-im-doing-instead-of-work.ul b/things-im-doing-instead-of-work.ul new file mode 100644 index 0000000..4ee8ba8 --- /dev/null +++ b/things-im-doing-instead-of-work.ul
@@ -0,0 +1,7 @@
1Things I'm doing instead of work
2
3writing a linkblog software
4drinking tea
5chatting with friends
6existential angst
7stressing about work \ No newline at end of file
diff --git a/types-of-lists-ll-supports.dl b/types-of-lists-ll-supports.dl new file mode 100644 index 0000000..93b0a36 --- /dev/null +++ b/types-of-lists-ll-supports.dl
@@ -0,0 +1,13 @@
1Types of lists ll supports
2
3all lists
4all lists are files with a header line at the top containing the list's title, then a series of lines forming the list items. items are at most 2 lines. blank lines are ignored. oh and list items are just html.
5
6ordered lists, unordered lists
7these are the regular <code>&lt;ol&gt;</code> and <code>&lt;ul&gt;</code> lists you know and love. just put one item on each line.
8
9anchor (link) lists
10make a list of links. items are separated by blank space and are 2 lines: the anchor (url) and its description.
11
12definition lists
13the lesser-known html-standard list type. same as anchor lists, but with <code>&lt;dt&gt;</code> on line one and <code>&lt;dd&gt;</code> on line two. \ No newline at end of file