From: Daniel Liu Date: Wed, 14 Jul 2021 17:35:55 +0000 (-0400) Subject: mount and rss X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=ae8408af2f6cac8cb64ff24aa1f2fe2c2255bf63;p=pinopress.git mount and rss --- diff --git a/README.md b/README.md index e7fb04f..4328dcb 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,9 @@ pinopress articles are written in an enhanced version of markdown. specification `$SITEURL` - the SITEURL variable you set in the pinopress config -`$USERVAR1` - global variable you can use however you want +`$USERGLOBAL1` - global variable you can use however you want -`$USERVAR2` - a second user defined global variable +`$USERGLOBAL2` - a second user defined global variable ### article only @@ -47,7 +47,13 @@ pinopress articles are written in an enhanced version of markdown. specification `$PUBLISHED_DATE` - the date/time the article was published, as set in the article header +`$DESCRIPTION` - brief description of the blog post + +`$USERLOCAL1` - article specific variable you can use for whatever you want + +`$USERLOCAL2` - another user local variable + ## mounts -coming soon... +many times, you would like to display a list of html elements somewhere in the page. **pinopress** solves this using mounts. mounts are simply comments that tell pinopress where to append template items. diff --git a/modules/md-header b/modules/md-header index f913fc9..4418395 100755 --- a/modules/md-header +++ b/modules/md-header @@ -11,6 +11,9 @@ case "$2" in name) propname=name;; published) propname=published;; tags) propname=tags;; + description) propname=description;; + userlocal1) propname=userlocal1;; + userlocal2) propname=userlocal2;; *) exit 1;; esac diff --git a/pinopress b/pinopress index 08b82cb..b457b13 100755 --- a/pinopress +++ b/pinopress @@ -5,8 +5,8 @@ # user variables SITEURL := https://blog.danieliu.xyz -USERVAR1 := -USERVAR2 := +USERGLOBAL1 := +USERGLOBAL2 := .PHONY: help build clean @@ -22,32 +22,40 @@ ARTICLE_LIST := $(basename $(shell ls $(SRC_DIR))) # some helper functions define export_common export SITEURL="$(SITEURL)" - export USERVAR1="$(USERVAR1)" - export USERVAR2="$(USERVAR2)" + export USERGLOBAL1="$(USERGLOBAL1)" + export USERGLOBAL2="$(USERGLOBAL2)" 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` + export DESCRIPTION=`./$(MODULE_DIR)/md-header "$(1)" description` + export USERLOCAL1=`./$(MODULE_DIR)/md-header "$(1)" userlocal1` + export USERLOCAL2=`./$(MODULE_DIR)/md-header "$(1)" userlocal2` # vvv this is sorta ugly vvv export ARTICLE_URL="$(SITEURL)/$(ARTICLE_PATH)/$(subst .md,.html,$(notdir "$(1)"))" endef +# usage: loop_article [dest] [template_filename] +define loop_article + for article_file in `ls $(SRC_DIR)`; do + $(call export_article,"$(SRC_DIR)/$$article_file") + envsubst < $(TEMPLATE_DIR)/$(2) | sed -i "//r /dev/stdin" "$(1)" + done +endef + help: echo 'pinopress help|build|clean' -build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(addprefix $(BUILD_DIR)/$(ARTICLE_PATH)/,$(addsuffix .html,$(ARTICLE_LIST))) +build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(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 + $(call loop_article,"$@",rollingitem.template.html) envsubst < "$@" | sponge "$@" .ONESHELL: @@ -55,6 +63,15 @@ $(BUILD_DIR)/archive.html: echo 'building archive file' $(export_common) cat $(TEMPLATE_DIR)/head.template.html $(TEMPLATE_DIR)/archivebody.template.html $(TEMPLATE_DIR)/foot.template.html > "$@" + $(call loop_article,"$@",archiveitem.template.html) + envsubst < "$@" | sponge "$@" + +.ONESHELL: +$(BUILD_DIR)/feed.xml: + echo 'building feed file' + $(export_common) + cat $(TEMPLATE_DIR)/feed.template.xml > "$@" + $(call loop_article,"$@",feeditem.template.xml) envsubst < "$@" | sponge "$@" .ONESHELL: @@ -71,5 +88,5 @@ $(BUILD_DIR)/$(ARTICLE_PATH)/%.html: $(SRC_DIR)/%.md clean: echo 'cleaning...' - rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/$(ARTICLE_PATH)/* + rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(BUILD_DIR)/$(ARTICLE_PATH)/* diff --git a/templates/archivebody.template.html b/templates/archivebody.template.html index 200d0cc..c7c6bef 100644 --- a/templates/archivebody.template.html +++ b/templates/archivebody.template.html @@ -1 +1,3 @@

Archive

+ + diff --git a/templates/feed.template.xml b/templates/feed.template.xml new file mode 100644 index 0000000..30759b4 --- /dev/null +++ b/templates/feed.template.xml @@ -0,0 +1,12 @@ + + + + +$SITEURL +$SITEURL + + + + + + diff --git a/templates/feeditem.template.xml b/templates/feeditem.template.xml new file mode 100644 index 0000000..8642ac0 --- /dev/null +++ b/templates/feeditem.template.xml @@ -0,0 +1,9 @@ + +$ARTICLE_TITLE +$ARTICLE_URL + + + + diff --git a/templates/rollingbody.template.html b/templates/rollingbody.template.html index 7ac26f9..fd68895 100644 --- a/templates/rollingbody.template.html +++ b/templates/rollingbody.template.html @@ -1,3 +1,4 @@

Rolling

- + +