diff mbox series

[RFC,v2] docs/website: Add Makefile to pre-generate the website

Message ID 20240206145353.19868-1-ismael@iodev.co.uk
State Changes Requested
Headers show
Series [RFC,v2] docs/website: Add Makefile to pre-generate the website | expand

Commit Message

Ismael Luceno Feb. 6, 2024, 2:53 p.m. UTC
Supports the current includes plus smu [0] lightweight markup.

[0] https://github.com/Gottox/smu
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 docs/website/Makefile    | 33 +++++++++++++++++++++++++++++++++
 docs/website/incfile.awk | 23 +++++++++++++++++++++++
 2 files changed, 56 insertions(+)
 create mode 100644 docs/website/Makefile
 create mode 100644 docs/website/incfile.awk

Comments

Ismael Luceno Feb. 6, 2024, 3:04 p.m. UTC | #1
On 06/Feb/2024 15:53, Ismael Luceno wrote:
> Supports the current includes plus smu [0] lightweight markup.
> 
> [0] https://github.com/Gottox/smu
> Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>

Changes from v1:
- Processes includes before passing through smu
- Still imperfect because smu mangles many html tags

To do:
- Maybe special-case html header and footer for smu files.
Yann E. MORIN Feb. 6, 2024, 3:10 p.m. UTC | #2
Ismael, All,

I'll do the rest of my review in this new iteration! ;-)

On 2024-02-06 15:53 +0100, Ismael Luceno spake thusly:
[--SNIP--]
> +${DEPLOYDIR}/%.html: ${SRCDIR}/%.smu ${conf-files}
> +	mkdir -p "${@D}"
> +	tmpfile=$$(mktemp) && \
> +	${AWK} -f incfile.awk $< | smu | tidy -q -m > "$$tmpfile" && \

Don't use pipes, otherwise we can't catch the failure of any
intermediate command. For example, if we can get the awk script to
properly fail in case of error, using pipes will not allow the Makefile
to catch issues.

Regards,
Yann E. MORIN.
diff mbox series

Patch

diff --git a/docs/website/Makefile b/docs/website/Makefile
new file mode 100644
index 000000000000..42069967f7ec
--- /dev/null
+++ b/docs/website/Makefile
@@ -0,0 +1,33 @@ 
+.PHONY: all
+all:
+
+# Avoid implicit rules
+MAKEFLAGS += -r
+
+AWK ?= mawk
+
+SRCDIR := ${CURDIR}
+DEPLOYDIR := ${CURDIR}/out
+
+src-pages != find ${SRCDIR} -maxdepth 1 -name \*.html -o -name \*.smu
+dst-pages := ${src-pages:${SRCDIR}/%=${DEPLOYDIR}/%}
+dst-pages := ${dst-pages:.smu=.html}
+
+all: ${dst-pages}
+
+conf-files := ${MAKEFILE_LIST}
+conf-files += $(wildcard ${HOME}/.tidyrc)
+conf-files += ${SRCDIR}/incfile.awk
+
+${DEPLOYDIR}/%.html: ${SRCDIR}/%.html ${conf-files}
+	mkdir -p "${@D}"
+	tmpfile=$$(mktemp) && \
+	${AWK} -f incfile.awk $< > "$$tmpfile" && \
+	{ tidy -q -m -i "$$tmpfile"; :; } && \
+	mv "$$tmpfile" $@
+
+${DEPLOYDIR}/%.html: ${SRCDIR}/%.smu ${conf-files}
+	mkdir -p "${@D}"
+	tmpfile=$$(mktemp) && \
+	${AWK} -f incfile.awk $< | smu | tidy -q -m > "$$tmpfile" && \
+	mv "$$tmpfile" $@
diff --git a/docs/website/incfile.awk b/docs/website/incfile.awk
new file mode 100644
index 000000000000..350a88e7b956
--- /dev/null
+++ b/docs/website/incfile.awk
@@ -0,0 +1,23 @@ 
+BEGIN {
+	FS="\""
+}
+
+{
+	do {
+		if (match($0, /^<!--#include file="([^"]*)" *-->$/)) {
+			file_stack[++file_cur] = $2
+		} else {
+			print
+		}
+		if (file_cur) {
+			e = getline < file_stack[file_cur]
+			if (!e) {
+				--file_cur
+			} else if (e == -1) {
+				printf "%s: read error\n", \
+					file_stack[file_cur] \
+					> "/dev/stderr"
+			}
+		}
+	} while (file_cur)
+}