# Copyright 2018, 2021, 2023 Vladimir Sedach # SPDX-License-Identifier: GPL-3.0-or-later # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Notable prerequisites: # GNU versions of date and stat # tidy http://www.html-tidy.org/ # xmllint https://gnome.pages.gitlab.gnome.org/libxml2/xmllint.html # ATOM schema https://cweiske.de/tagebuch/atom-validation.htm parts = src/parts/ header = $(parts)header.html footer = $(parts)footer.html blog-header = $(parts)blog-header.html blog-topics = have-emacs-will-hack/topics pages := $(subst src/,htdocs/,$(wildcard src/*.html)) blogposts := $(shell (for x in $(sort $(wildcard have-emacs-will-hack/posts/*.html)); do echo $$x; done) | sed '1!G;h;$$!d') blog-entries := $(subst have-emacs-will-hack/posts/,htdocs/have-emacs-will-hack/,$(blogposts)) all: $(pages) $(blog-entries) htdocs/have-emacs-will-hack/files/current/Makefile htdocs/have-emacs-will-hack/index.html htdocs/have-emacs-will-hack/feed.xml deploy: rsync -azv --delete --exclude='.well-known/' --exclude='source-code-repositories/' --exclude='tmp/' --chmod=o=rX htdocs/ vas@oneofus.la:/var/www/htdocs/oneofus.la/ preview: cd htdocs && python3 -m http.server 8081 # common functions add-header = @cat $(header) > $@ add-body = @cat $< >> $@ add-last-modified = @echo 'Last modified' `stat --printf=%y $(1) | cut -c-10`'' >> $@ define add-footer = @cat $(footer) >> $@ @tidy -q -e $@ endef # site htdocs/%.html: src/%.html $(header) $(footer) @echo Building $@ $(add-header) $(add-body) $(call add-last-modified,$@) $(add-footer) # blog add-blog-header = @cat $(blog-header) >> $@ post-date = $(shell echo $(notdir $(1)) | cut -c-10) post-title = "$(shell head -n1 $(1))" post-category = $(shell sed -n 2p $(1)) post-category-anchor = $(shell echo $(1) | tr ' ' _) post-category-unanchor = $(shell echo $(1) | tr _ ' ') post-content = tail -n +3 htdocs/have-emacs-will-hack/%.html: have-emacs-will-hack/posts/%.html $(header) $(footer) $(blog-header) @echo Building $@ $(add-header) $(add-blog-header) @date --date=$(call post-date,$<) +"%B %e, %Y" >> $@ @echo '

'$(call post-title,$<)'

' >> $@ @echo '

Topic: '$(call post-category,$<)'

' >> $@ @$(post-content) $< >> $@ @echo '
' >> $@ $(add-footer) define add-blog-entry-list = @echo '' >> $@ @$(foreach post,$(1),echo '' >> $@;) endef define make-blog-topic-list-files = @-rm $(wildcard $(blog-topics)/*) @$(foreach post,$(blogposts),echo $(post) >> '$(blog-topics)/$(call post-category-anchor,$(call post-category,$(post)))';) endef define output-topic-index = echo '

'$(call post-category-unanchor,$(notdir $(1)))'

' >> $@ $(call add-blog-entry-list,$(shell cat $(1))) @echo '
'$(call post-date,$(post))''$(call post-title,$(post))'
' >> $@; endef define add-blog-topics = $(call make-blog-topic-list-files) @$(foreach topic-file,$(sort $(wildcard $(blog-topics)/*)),$(call output-topic-index,$(topic-file))) endef htdocs/have-emacs-will-hack/index.html: $(blogposts) $(header) $(footer) $(blog-header) @echo Building blog index page $(add-header) $(add-blog-header) @echo '

ATOM feed

' >> $@ @echo '

All Posts

' >> $@ $(call add-blog-entry-list,$(blogposts)) @echo '' >> $@ @echo '

By Topic

' >> $@ $(call add-blog-topics) $(call add-last-modified,$@) $(add-footer) # this Makefile as featured in the blog htdocs/have-emacs-will-hack/files/current/Makefile: Makefile @cp $< $@ # blog feed, RFC 4287 Atom recent-posts := $(wordlist 1,6,$(blogposts)) blog-base = https://oneofus.la/have-emacs-will-hack/ htdocs/have-emacs-will-hack/feed.xml: $(recent-posts) have-emacs-will-hack/feed-header.xml @echo Building blog ATOM feed @cat have-emacs-will-hack/feed-header.xml > $@ @echo ''$(call post-date,$(firstword $(recent-posts)))'T12:00:00Z' >> $@ @$(foreach post,$(recent-posts),echo ''$(call post-title,$(post))''$(blog-base)$(notdir $(post))''$(call post-date,$(post))'T12:00:00Z' >> $@; $(post-content) $(post) | recode utf8..h0 >> $@; echo '' >> $@;) @echo '' >> $@ @xmllint --noout --relaxng atom-schema.rng htdocs/have-emacs-will-hack/feed.xml # front page htdocs/index.html: src/index.html $(recent-posts) $(parts)index-other-things.html $(header) $(footer) @echo Building front page $(add-header) $(add-body) $(call add-blog-entry-list,$(recent-posts)) @cat $(parts)index-other-things.html >> $@ $(call add-last-modified,$@) $(add-footer)