commit 848197c
shrub
·
2026-05-18 16:29:55 +0000 UTC
parent 653ae91
remove js, add small usage guide, remove old metadata from example
7 files changed,
+88,
-67
M
Makefile
+1,
-1
1@@ -51,7 +51,7 @@ $(OUT_DIR)/pub/style.css: pub/style.css
2
3 $(OUT_DIR)/mandoc.css: pub/mandoc.css
4 @mkdir -p "$(dir $@)"
5- @if [ -f "$(SRC_DIR)/mandoc.css" ]; then cp "$(SRC_DIR)/mandoc.css" "$@"; else cp pub/mandoc.css "$@"; fi
6+ @if [ -f "$(SRC_DIR)/_mite/mandoc.css" ]; then cp "$(SRC_DIR)/_mite/mandoc.css" "$@"; else cp pub/mandoc.css "$@"; fi
7
8 serve: build
9 $(HELPER) serve "$(OUT_DIR)" "$(PORT)"
+42,
-1
1@@ -9,4 +9,45 @@ make
2 make serve
3 ```
4
5-documentation and usage guide to come; you can take a look at the example site to get an idea.
6+how to
7+------
8+
9+1. make a directory for your site at `sites/mywebsite/`.
10+2. add `sites/mywebsite/manifest.mk`. this includes the metadata about your site so the makefile knows how to build it. you can really write it however you want as long as you provide the right variables, but this is the template i recomend following:
11+```
12+SITE_TITLE = mywebsite
13+SITE_SUBTITLE = mywebsiteisthebestwebsite.
14+
15+DIRS = \ # list all directories in your site
16+ $(OUT_DIR) \
17+ $(OUT_DIR)/docs \
18+ $(OUT_DIR)/pub
19+
20+HTML_TARGETS = # leave this empty, see next step
21+STATIC_TARGETS = # you should put here any static files you want copied into the output, like images etc
22+
23+include $(SRC_DIR)/mk/*
24+```
25+
26+3. then add some make fragments in `sites/your.site/mk/*.mk`, one for every page you have:
27+```
28+PAGE := index
29+HTML_TARGETS := $(HTML_TARGETS) $(OUT_DIR)/$(PAGE).html # add the page to the list of html targets so make knows to build it.
30+
31+TITLE.$(PAGE) = home # displayed at the top-middle of page
32+OS.$(PAGE) = mywebsite # displayed at the bottom-corner of the page
33+URL.$(PAGE) := /$(PAGE).html
34+
35+#you should declare dependencies like this so make can incrementally rebuild for each page
36+$(OUT_DIR)/index.html: $(SRC_DIR)/mk/index.mk
37+$(OUT_DIR)/index.raw.html: $(SRC_DIR)/index.1
38+```
39+4. add source files like `sites/mywebsite/index.1`. you should write them in mdoc.
40+5. build with `make SITE=mywebsite`
41+
42+if you want to do css:
43+
44+- put site css at `sites/mywebsite/_mite/style.css` to append it after `pub/style.css`.
45+- put `sites/mywebsite/_mite/mandoc.css` to replace the default openbsd mandoc css
46+
47+you can look at the example in sites/example.com to get a good idea, or to use a starting point.
+45,
-44
1@@ -1,4 +1,4 @@
2-#!/bin/sh
3+#!/bin/mksh
4 set -eu
5 #helper script for mite.
6 cmd="${1:-}"
7@@ -26,6 +26,8 @@ raw)
8 body)
9 in="$1"
10 out="$2"
11+ # extract and normalize only the rendered body from mandocs output
12+ # this strips mandocs header and footer tables because we do our own
13 awk '
14 function lower(s) { return tolower(s) }
15 function decode_html_entities(s) {
16@@ -44,6 +46,7 @@ body)
17 function push_litline(s) { lit[++lit_n] = s }
18 function push_preline(s) { pre[++pre_n] = s }
19 function flushblock( i, line, non_empty, all_htmlish) {
20+ # if it looks like an html and quacks like an html...
21 non_empty = 0
22 all_htmlish = 1
23 for (i = 1; i <= pre_n; i++) {
24@@ -134,51 +137,54 @@ sidebar)
25 src_dir="$2"
26 {
27 echo '<ul class="side-nav side-tree">'
28+ # parse the page metadata from mk/*.mk and emit rows
29+ # path|url|title-label
30 awk '
31 function flush() {
32- if (page != "" && nav != "" && url != "") {
33+ if (page != "" && title != "" && url != "") {
34 if (page == "index") return
35 u = url
36 gsub(/\$\(PAGE\)/, page, u)
37- printf "%s|%s|%s\n", page, u, nav
38+ printf "%s|%s|%s\n", page, u, title
39 }
40 }
41 FNR==1 {
42 if (NR > 1) flush()
43- page=""; nav=""; url=""
44+ page=""; title=""; url=""
45 }
46 /^PAGE := / { page=substr($0, 9) }
47- /^NAV\.\$\(PAGE\) = / { nav=substr($0, 15) }
48+ /^TITLE\.\$\(PAGE\) = / { title=substr($0, 17) }
49 /^URL\.\$\(PAGE\) := / { url=substr($0, 16) }
50 END { flush() }
51 ' "$src_dir"/mk/*.mk \
52 | sort \
53 | awk -F'|' '
54+ # build the dir tree
55 function close_to(n, i) {
56- for (i=level; i>n; i--) {
57+ for (i = level; i > n; i--) {
58 print "</ul></details></li>"
59 }
60 level = n
61 }
62- BEGIN { level=0 }
63+ BEGIN { level = 0 }
64 {
65- path=$1; url=$2; nav=$3
66+ path=$1; url=$2; title=$3
67 n = split(path, p, "/")
68 dirs = n - 1
69 common = 0
70- for (i=1; i<=dirs && i<=level; i++) {
71+ for (i = 1; i <= dirs && i <= level; i++) {
72 if (p[i] == dstack[i]) common = i
73 else break
74 }
75 close_to(common)
76- for (i=common+1; i<=dirs; i++) {
77+ for (i = common + 1; i <= dirs; i++) {
78 dstack[i] = p[i]
79 dirpath = p[1]
80- for (j=2; j<=i; j++) dirpath = dirpath "/" p[j]
81- printf "<li class=\"dir\"><details data-dir=\"%s\"><summary>%s</summary><ul>\n", dirpath, p[i]
82+ for (j = 2; j <= i; j++) dirpath = dirpath "/" p[j]
83+ printf "<li class=\"dir\"><details data-dir=\"%s\"><summary>%s/</summary><ul>\n", dirpath, p[i]
84 }
85 level = dirs
86- printf "<li class=\"page\"><a href=\"%s\">› %s</a></li>\n", url, nav
87+ printf "<li class=\"page\"><a href=\"%s\">› %s</a></li>\n", url, title
88 }
89 END { close_to(0) }
90 '
91@@ -244,37 +250,32 @@ page)
92 if [ -n "$site_subtitle" ]; then
93 printf '<div class="sidebar-subtitle">%s</div>\n' "$site_subtitle"
94 fi
95- awk -v cur="$url" '{ line=$0; if (index(line, "href=\"" cur "\"")>0) sub(/<a /,"<a class=\"thisPage\" ",line); print line }' "$out_dir/sidebar.html"
96- echo '<div class="sidebar-powered">powered by make n mdoc</div>'
97- cat <<'EOF'
98-<script>
99-(function () {
100- var key = "mite.sidebar.open";
101- var state = {};
102- try { state = JSON.parse(localStorage.getItem(key) || "{}"); } catch (_) {}
103- var details = document.querySelectorAll(".sidebar details[data-dir]");
104- for (var i = 0; i < details.length; i++) {
105- var d = details[i];
106- var id = d.getAttribute("data-dir");
107- if (Object.prototype.hasOwnProperty.call(state, id)) d.open = !!state[id];
108- }
109- var cur = document.querySelector(".sidebar a.thisPage");
110- if (cur) {
111- var p = cur.parentElement;
112- while (p && p !== document.body) {
113- if (p.tagName === "DETAILS") p.open = true;
114- p = p.parentElement;
115- }
116- }
117- for (var j = 0; j < details.length; j++) {
118- details[j].addEventListener("toggle", function () {
119- state[this.getAttribute("data-dir")] = this.open;
120- try { localStorage.setItem(key, JSON.stringify(state)); } catch (_) {}
121- });
122- }
123-})();
124-</script>
125-EOF
126+ # for some current page link open only the ancestor <details>
127+ # before i had some js to do this and it had one or two extra things it could do,
128+ # like opening multiple dirs at once and keeping the open ones open, but this
129+ # is probably better, because js bad or smth. (thanks sewn)
130+ awk -v cur="$url" '
131+ {
132+ line = $0
133+ if (index(line, "href=\"" cur "\"") > 0) sub(/<a /, "<a class=\"thisPage\" ", line)
134+ lines[++n] = line
135+ if (line ~ /<details[^>]*data-dir=/) stack[++sp] = n
136+ if (line ~ /class="thisPage"/) {
137+ for (i = 1; i <= sp; i++) keep_open[stack[i]] = 1
138+ }
139+ if (line ~ /<\/ul><\/details><\/li>/ && sp > 0) sp--
140+ }
141+ END {
142+ for (i = 1; i <= n; i++) {
143+ line = lines[i]
144+ if (keep_open[i] && line ~ /<details/ && line !~ /<details[^>]* open([[:space:]]|>)/) {
145+ sub(/<details/, "<details open", line)
146+ }
147+ print line
148+ }
149+ }
150+ ' "$out_dir/sidebar.html"
151+ echo '<div class="sidebar-powered"><a href="https://git.sr.ht/~shrub900/mite">powered by mite</a></div>'
152 echo '</aside>'
153 echo '<main class="content">'
154 printf '<div class="head" role="doc-pageheader" aria-label="Manual header line"><span class="head-ltitle">%s</span> <span class="head-vol">%s</span> <span class="head-rtitle">%s</span></div>\n' "$label" "$title" "$label"
+0,
-2
1@@ -6,9 +6,7 @@ DIRS = \
2 $(OUT_DIR)/docs \
3 $(OUT_DIR)/pub
4
5-MDOC_FILES =
6 HTML_TARGETS =
7 STATIC_TARGETS =
8-META_PAGES =
9
10 include $(SRC_DIR)/mk/*
+0,
-7
1@@ -1,16 +1,9 @@
2 PAGE := docs/about
3-MDOC_FILES := $(MDOC_FILES) $(PAGE).1
4 HTML_TARGETS := $(HTML_TARGETS) $(OUT_DIR)/$(PAGE).html
5-META_PAGES := $(META_PAGES) $(PAGE)
6
7 TITLE.$(PAGE) = about
8 OS.$(PAGE) = example.com
9 URL.$(PAGE) := /$(PAGE).html
10-LABEL.$(PAGE) = about(7)
11-NAV.$(PAGE) = about
12-DEPTH.$(PAGE) = 1
13
14 $(OUT_DIR)/docs/about.html: $(SRC_DIR)/mk/docs-about.mk
15-
16-
17 $(OUT_DIR)/docs/about.raw.html: $(SRC_DIR)/docs/about.1
1@@ -1,16 +1,9 @@
2 PAGE := docs/getting-started
3-MDOC_FILES := $(MDOC_FILES) $(PAGE).1
4 HTML_TARGETS := $(HTML_TARGETS) $(OUT_DIR)/$(PAGE).html
5-META_PAGES := $(META_PAGES) $(PAGE)
6
7 TITLE.$(PAGE) = getting started
8 OS.$(PAGE) = example.com
9 URL.$(PAGE) := /$(PAGE).html
10-LABEL.$(PAGE) = getting-started(7)
11-NAV.$(PAGE) = getting started
12-DEPTH.$(PAGE) = 1
13
14 $(OUT_DIR)/docs/getting-started.html: $(SRC_DIR)/mk/docs-getting-started.mk
15-
16-
17 $(OUT_DIR)/docs/getting-started.raw.html: $(SRC_DIR)/docs/getting-started.1
+0,
-5
1@@ -1,14 +1,9 @@
2 PAGE := index
3-MDOC_FILES := $(MDOC_FILES) $(PAGE).1
4 HTML_TARGETS := $(HTML_TARGETS) $(OUT_DIR)/$(PAGE).html
5-META_PAGES := $(META_PAGES) $(PAGE)
6
7 TITLE.$(PAGE) = home
8 OS.$(PAGE) = example.com
9 URL.$(PAGE) := /$(PAGE).html
10-LABEL.$(PAGE) = home(7)
11-NAV.$(PAGE) = home
12-DEPTH.$(PAGE) = 0
13
14 $(OUT_DIR)/index.html: $(SRC_DIR)/mk/index.mk
15 $(OUT_DIR)/index.raw.html: $(SRC_DIR)/index.1