From c2a180be93daf0ae77953d548c5bd658818452a3 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 13 Jul 2021 00:18:28 -0400 Subject: [PATCH] rolling items --- README.md | 14 +++++++++++++- pinopress | 29 ++++++++++++++++++++++------- templates/archiveitem.template.html | 1 + templates/rollingbody.template.html | 2 ++ templates/rollingitem.template.html | 3 +++ 5 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 templates/archiveitem.template.html create mode 100644 templates/rollingitem.template.html diff --git a/README.md b/README.md index 4eaa2c2..e7fb04f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,16 @@ built in features include markdown generated blog articles, and a rss feed. ## templates -templates are html snippets that you can customize. these templates are then pieced together to form the final html page. edit them to your liking. they can be found in the `templates/` directory. +templates are html snippets that you can customize. these templates are then pieced together to form the final html page. edit them to your liking. they can be found in the `templates/` directory. Here's a brief description of each one: + +template | description +------------------|----------- +head | html before body +foot | html after body +archivebody | everything inside body of archive page +archiveitem | +rollingbody | everything inside body of rolling page +rollingitem | ## modules @@ -27,12 +36,15 @@ pinopress articles are written in an enhanced version of markdown. specification ### global `$SITEURL` - the SITEURL variable you set in the pinopress config + `$USERVAR1` - global variable you can use however you want + `$USERVAR2` - a second user defined global variable ### article only `$ARTICLE_TITLE` - title of article, as set in article header + `$PUBLISHED_DATE` - the date/time the article was published, as set in the article header ## mounts diff --git a/pinopress b/pinopress index 5157f99..08b82cb 100755 --- a/pinopress +++ b/pinopress @@ -1,5 +1,9 @@ #!/usr/bin/make -sf +## pinopress - the simple static blog generator +## dependencies: sponge + +# user variables SITEURL := https://blog.danieliu.xyz USERVAR1 := USERVAR2 := @@ -12,7 +16,7 @@ BUILD_DIR := build SRC_DIR := articles MODULE_DIR := modules -ARTICLE_PATH := $(BUILD_DIR)/article +ARTICLE_PATH := article ARTICLE_LIST := $(basename $(shell ls $(SRC_DIR))) # some helper functions @@ -22,16 +26,28 @@ define export_common export USERVAR2="$(USERVAR2)" endef +# usage: export_article [input md] +define export_article + export ARTICLE_TITLE=`./$(MODULE_DIR)/md-header "$(1)" name` + export PUBLISHED_DATE=`./$(MODULE_DIR)/md-header "$(1)" published` + # vvv this is sorta ugly vvv + export ARTICLE_URL="$(SITEURL)/$(ARTICLE_PATH)/$(subst .md,.html,$(notdir "$(1)"))" +endef + help: echo 'pinopress help|build|clean' -build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(ARTICLE_PATH)/$(addsuffix .html,$(ARTICLE_LIST)) +build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(addprefix $(BUILD_DIR)/$(ARTICLE_PATH)/,$(addsuffix .html,$(ARTICLE_LIST))) .ONESHELL: $(BUILD_DIR)/rolling.html: echo 'building rolling file' $(export_common) cat $(TEMPLATE_DIR)/head.template.html $(TEMPLATE_DIR)/rollingbody.template.html $(TEMPLATE_DIR)/foot.template.html > "$@" + for article_file in `ls $(SRC_DIR)`; do + $(call export_article,"$(SRC_DIR)/$$article_file") + envsubst < $(TEMPLATE_DIR)/rollingitem.template.html | sed -i "//r /dev/stdin" "$@" + done envsubst < "$@" | sponge "$@" .ONESHELL: @@ -42,11 +58,10 @@ $(BUILD_DIR)/archive.html: envsubst < "$@" | sponge "$@" .ONESHELL: -$(ARTICLE_PATH)/%.html: articles/%.md - echo 'parsing $^' +$(BUILD_DIR)/$(ARTICLE_PATH)/%.html: $(SRC_DIR)/%.md + echo "parsing $<" $(export_common) - export ARTICLE_TITLE="$(shell ./$(MODULE_DIR)/md-header "$<" name)" - export PUBLISHED_DATE="$(shell ./$(MODULE_DIR)/md-header "$<" published)" + $(call export_article,"$<") cat $(TEMPLATE_DIR)/head.template.html > "$@" # module pipeline starts here ./$(MODULE_DIR)/md "$^" >> "$@" @@ -56,5 +71,5 @@ $(ARTICLE_PATH)/%.html: articles/%.md clean: echo 'cleaning...' - rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(ARTICLE_PATH)/* + rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/$(ARTICLE_PATH)/* diff --git a/templates/archiveitem.template.html b/templates/archiveitem.template.html new file mode 100644 index 0000000..867a94d --- /dev/null +++ b/templates/archiveitem.template.html @@ -0,0 +1 @@ +
  • $ARTICLE_TITLE
  • diff --git a/templates/rollingbody.template.html b/templates/rollingbody.template.html index 2123bde..7ac26f9 100644 --- a/templates/rollingbody.template.html +++ b/templates/rollingbody.template.html @@ -1 +1,3 @@

    Rolling

    + + diff --git a/templates/rollingitem.template.html b/templates/rollingitem.template.html new file mode 100644 index 0000000..52803ec --- /dev/null +++ b/templates/rollingitem.template.html @@ -0,0 +1,3 @@ +
    +

    $ARTICLE_TITLE

    +
    -- 2.20.1