diff mbox series

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

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

Commit Message

Ismael Luceno Feb. 6, 2024, 4:25 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>
---

Notes:
    Changes since v2:
    - Integrate with toplevel makefile
    - Use parethesis instead of curly braces for variables
    - Removed smu rule
    - Copy resources to output directory too
    - Filter-out footer.html & header.html

 Makefile                 |  8 ++++++--
 docs/website/incfile.awk | 30 ++++++++++++++++++++++++++++++
 docs/website/website.mk  | 31 +++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 docs/website/incfile.awk
 create mode 100644 docs/website/website.mk

Comments

Ismael Luceno Feb. 6, 2024, 4:28 p.m. UTC | #1
Ignore the commit message, it only supports the server-side includes
now.
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index ac625152c678..cd56bc268917 100644
--- a/Makefile
+++ b/Makefile
@@ -123,7 +123,8 @@  endif
 noconfig_targets := menuconfig nconfig gconfig xconfig config oldconfig randconfig \
 	defconfig %_defconfig allyesconfig allnoconfig alldefconfig syncconfig release \
 	randpackageconfig allyespackageconfig allnopackageconfig \
-	print-version olddefconfig distclean manual manual-% check-package
+	print-version olddefconfig distclean manual manual-% check-package \
+	website
 
 # Some global targets do not trigger a build, but are used to collect
 # metadata, or do various checks. When such targets are triggered,
@@ -1180,6 +1181,7 @@  help:
 	@echo '  graph-depends          - generate graph of the dependency tree'
 	@echo '  graph-size             - generate stats of the filesystem size'
 	@echo '  list-defconfigs        - list all defconfigs (pre-configured minimal systems)'
+	@echo '  website                - build website'
 	@echo
 	@echo 'Miscellaneous:'
 	@echo '  source                 - download all sources needed for offline-build'
@@ -1234,7 +1236,7 @@  release: OUT = buildroot-$(BR2_VERSION)
 # documentation to the git output
 release:
 	git archive --format=tar --prefix=$(OUT)/ HEAD > $(OUT).tar
-	$(MAKE) O=$(OUT) manual-html manual-text manual-pdf
+	$(MAKE) O=$(OUT) manual-html manual-text manual-pdf website
 	$(MAKE) O=$(OUT) distclean
 	tar rf $(OUT).tar $(OUT)
 	gzip -9 -c < $(OUT).tar > $(OUT).tar.gz
@@ -1253,6 +1255,8 @@  check-package:
 	$(Q)./utils/check-package --failed-only `git ls-tree -r --name-only HEAD` \
 		> .checkpackageignore
 
+include docs/website/website.mk
+
 include docs/manual/manual.mk
 -include $(foreach dir,$(BR2_EXTERNAL_DIRS),$(sort $(wildcard $(dir)/docs/*/*.mk)))
 
diff --git a/docs/website/incfile.awk b/docs/website/incfile.awk
new file mode 100644
index 000000000000..e8ae571de271
--- /dev/null
+++ b/docs/website/incfile.awk
@@ -0,0 +1,30 @@ 
+BEGIN {
+	FS="\""
+}
+
+FNR == 1 {
+	curdir = FILENAME
+	sub(/[^/]*$/, "", curdir)
+	if (curdir !~ /[/]$/)
+		curdir = curdir "/"
+}
+
+{
+	do {
+		if (match($0, /^<!--#include file="([^"]*)" *-->$/)) {
+			file_stack[++file_cur] = curdir $2
+		} else {
+			print
+		}
+		if (file_cur > 0) {
+			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 > 0)
+}
diff --git a/docs/website/website.mk b/docs/website/website.mk
new file mode 100644
index 000000000000..d3f7b28aaa07
--- /dev/null
+++ b/docs/website/website.mk
@@ -0,0 +1,31 @@ 
+################################################################################
+#
+# The Buildroot website
+#
+################################################################################
+
+AWK ?= mawk
+
+website-dir = $(TOPDIR)/docs/website
+website-src = $(wildcard $(website-dir)/*.html)
+website-gen = $(filter-out %/header.html %/footer.html,\
+	$(website-src:$(website-dir)/%=$(O)/website/%))
+website-res = $(patsubst $(website-dir)/%,$(O)/website/%,$(wildcard \
+	$(website-dir)/js/*.js \
+	$(website-dir)/css/*.css \
+	$(website-dir)/fonts/* \
+	$(website-dir)/images/* \
+))
+
+website: $(website-gen) $(website-res)
+
+$(website-res): $(O)/website/%: $(website-dir)/%
+	install -m644 -D $< $@
+
+website-dep = $(website-dir)/website.mk $(website-dir)/incfile.awk
+
+$(O)/website/%.html: $(website-dir)/%.html $(website-dep)
+	mkdir -p "$(@D)"
+	tmpfile=$$(mktemp) && \
+	$(AWK) -f $(website-dir)/incfile.awk $< > "$$tmpfile" && \
+	mv "$$tmpfile" $@