diff options
author | Case Duckworth | 2024-03-11 23:00:20 -0500 |
---|---|---|
committer | Case Duckworth | 2024-03-11 23:00:20 -0500 |
commit | 05d812d91ec3a1d66f630afaf6a26eb0d4df12a7 (patch) | |
tree | a134f2112460cca9f00295d6fe0b71d9deab49de | |
download | ll-05d812d91ec3a1d66f630afaf6a26eb0d4df12a7.tar.gz ll-05d812d91ec3a1d66f630afaf6a26eb0d4df12a7.zip |
First commit
-rw-r--r-- | .gitignore | 3 | ||||
-rwxr-xr-x | ll | 118 | ||||
-rw-r--r-- | things-im-doing-instead-of-work.ul | 7 | ||||
-rw-r--r-- | types-of-lists-ll-supports.dl | 13 |
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 | ||
3 | index.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 | ||
4 | BASE_URL=. | ||
5 | SITE_TITLE="a listlog" | ||
6 | SITE_COPYRIGHT="Case Duckworth" | ||
7 | BACK_LINK=index.html,back | ||
8 | |||
9 | wrap() { | ||
10 | title="$(sed 1q "$1")" | ||
11 | cat <<HEAD | ||
12 | <!DOCTYPE html> | ||
13 | <title>$title</title> | ||
14 | <style> | ||
15 | body{max-width:48em;font:20px/1.4 serif;margin:auto;padding:1em;} | ||
16 | footer{position:absolute;bottom:0;left:0;padding:1em;background:white;} | ||
17 | dt{font-weight:bold;} | ||
18 | </style> | ||
19 | <body> | ||
20 | <!-- LIST_START --> | ||
21 | <h1>$title</h1> | ||
22 | HEAD | ||
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> | ||
32 | FOOT | ||
33 | } | ||
34 | |||
35 | # Library | ||
36 | list()(tag="$1";shift;echo "<$tag>"; sed 1d|awk "$@"; echo "</$tag>") | ||
37 | # unordered list | ||
38 | ul()(list ul '/^$/{next}{printf "<li>%s</li>\n",$0}') | ||
39 | # ordered list | ||
40 | ol()(list ol '/^$/{next}{printf "<li>%s</li>\n",$0}') | ||
41 | # anchor (link) list | ||
42 | al()(list ul -F"\n" -vRS= '{printf "<li><a href=\"%s\">%s</a></li>\n",$1,$2}') | ||
43 | # definition list | ||
44 | dl()(list dl -F"\n" -vRS= '{printf "<dt>%s</dt>\n<dd>%s</dd>\n",$1,$2}') | ||
45 | |||
46 | rss() { | ||
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> | ||
56 | HEAD | ||
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 | } | ||
73 | function 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 | } | ||
80 | function 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> | ||
92 | FOOT | ||
93 | } | ||
94 | |||
95 | # Main | ||
96 | main() { | ||
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 | |||
118 | main "$@" | ||
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 @@ | |||
1 | Things I'm doing instead of work | ||
2 | |||
3 | writing a linkblog software | ||
4 | drinking tea | ||
5 | chatting with friends | ||
6 | existential angst | ||
7 | stressing 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 @@ | |||
1 | Types of lists ll supports | ||
2 | |||
3 | all lists | ||
4 | all 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 | |||
6 | ordered lists, unordered lists | ||
7 | these are the regular <code><ol></code> and <code><ul></code> lists you know and love. just put one item on each line. | ||
8 | |||
9 | anchor (link) lists | ||
10 | make a list of links. items are separated by blank space and are 2 lines: the anchor (url) and its description. | ||
11 | |||
12 | definition lists | ||
13 | the lesser-known html-standard list type. same as anchor lists, but with <code><dt></code> on line one and <code><dd></code> on line two. \ No newline at end of file | ||