#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # index.mk # #> Index Gemini site content #> #> This Makefile builds content indicies for a Gemini site. #> # # Allowing posts to be m4 files introduces complexity without clear benefit. # Thus we are # # Strategy: # 1. Mark all *.gmi files as posts. # 2. Limit macros to: # a. Section index # b. Tagged index # c. Header # d. Footer # 4. Create index entries for each *.gmi file. # 5. Build the full list of tags. # 6. Generate the post as `cat footer.gmi post.gmi footer.gmi`. # 7. Build the tagged index files from the list of tags. # 8. Build index.gmi from tag list. # # The key challenge is step 7. We do not know how to build this until we # completed step 5. Two possible approaches: # 1. Create a macro # 2. Recurse into another Makefile. # # © 2023 Andrew Stryker #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# #-----------------------------------------------------------------------------# # # Configuration # #-----------------------------------------------------------------------------# # Record the name of this Makefile self ::= $(lastword ${MAKEFILE_LIST}) # Load environment variables if needed--not the case when this is called from # the main Makefile ifndef ENV_LOADED # Assume the base directory is two levels up if not defined MAKO_DIR ?= ../.. include ${MAKO_DIR}/environment.mk endif # Define using the same definition as in the main Makefile build_date_msg ?= This page was built on $$(date). # Define special files index_template ::= index.gmi.m4 index ::= ${STAGING_SECTION}/index.gmi header_template ::= header.gmi.m4 header ::= ${WORKING_SECTION}/header.gmi footer_template ::= footer.gmi.m4 footer ::= ${WORKING_SECTION}/footer.gmi # Capture all posts as Gemtext files that begin with an ISO formatted date posts_gmi ::= $(shell ls *.gmi | grep "[[:digit:]]\{4\}\(-[[:digit:]]\{2\}\)\{2\}") posts ::= $(addprefix ${STAGING_SECTION}/, ${posts_gmi}) entries ::= $(addprefix ${WORKING_SECTION}/, ${posts_gmi:.gmi=.lnk}) TAG_LIST ::= ${WORKING_SECTION}/tag-list export TAG_LIST # Create list of potential dependencies of *.gmi.m4 templates template_depends ::= $(notdir $(filter-out %.gmi.m4 _% %~, $(wildcard *))) #-----------------------------------------------------------------------------# # # User interface # #> This makefile supports the following targets: #> #-----------------------------------------------------------------------------# .PHONY: default build clean show help create # define the default target explicitly default: create create: #> Create a new post (default) @if [ -z $${EDITOR} ]; then \ python3 create-post.py; \ else \ python3 create-post.py --edit; \ fi build: ${index} #> Build the site (default) @echo "✓ Completed processing ${content_section}" @echo show: #> Show enironment variables with values @echo staging area: ${STAGING} @echo workspace: ${WORKSPACE} @echo post_index: ${post_index} @echo ${build_date_msg} @echo targets: ${post_targets} @echo header: ${header} @echo footer: ${footer} @echo tag list: ${TAG_LIST} clean: #> Delete generated files @rm -rf ${STAGING} ${WORKSPACE} @echo "\t✓ Deleted intermediate files" @echo "\t✓ Deleted all posts in ${STAGING}" help: #> Display this help message @awk -f ${AWKHELP} ${self} #-----------------------------------------------------------------------------# # # File system interface # #-----------------------------------------------------------------------------# ${header} ${footer}: ${WORKING_SECTION}/%: % ${template_depends} @mkdir -p ${WORKING_SECTION} @m4 --include=${MAKO_DIR} $< > $@ @echo "\t✓ Created: $@" ${posts}: ${STAGING_SECTION}/%: % ${header} ${footer} @mkdir -p ${STAGING_SECTION} @cat ${header} $< ${footer} > $@ @echo "${build_date_msg}" >> $@ @echo "\t✓ Created $@" ${entries}: ${WORKING_SECTION}/%.lnk: ${MAKO_DIR}/create-index-entry.awk %.gmi @mkdir -p ${WORKING_SECTION} @awk -f $^ > $@ @echo "\t✓ Created: $@" ${TAG_LIST}: ${entries} @cat $^ | sort --unique | \ sed -e '/^---/ d; s/^\([a-zA-Z0-09]\+\).*/=> \1.gmi \1/' > $@ @echo "\t✓ Created the tags list" ${index}: ${index_template} ${header} ${footer} ${posts} ${TAG_LIST} @${MAKE} -f ${TAG_MAKE} build @m4 --include=.. \ --define=TAGS=${tags_list} \ --define=POSTS=${post_entry} \ --define=HEADER=${header} \ --define=FOOTER=${footer} \ $< > $@ @echo "✓ Created: $@" #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#