From: Daniel Liu Date: Wed, 14 Jul 2021 18:22:49 +0000 (-0400) Subject: moved header export to inside module X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=cc7b64f958b577507c4fdf21959f156d8b7f3c04;p=pinopress.git moved header export to inside module --- diff --git a/modules/md-header b/modules/md-header index 4418395..e671ea8 100755 --- a/modules/md-header +++ b/modules/md-header @@ -2,19 +2,19 @@ ## module to read meta in header of md file ## usage: -## md-header [md_filepath] [header_name] +## md-header [md_filepath] -[ "$#" -ne 2 ] && { echo "Incorrect usage"; exit 1; } +[ "$#" -ne 1 ] && { echo "Incorrect usage"; exit 1; } -propname="" -case "$2" in - name) propname=name;; - published) propname=published;; - tags) propname=tags;; - description) propname=description;; - userlocal1) propname=userlocal1;; - userlocal2) propname=userlocal2;; - *) exit 1;; -esac +# usage: getprop [path] [prop] +getprop() { + sed -nE "s/^-- $2: (.*)$/\1/p" "$1" +} -sed -nE "s/^-- ${propname}: (.*)$/\1/p" "$1" +export ARTICLE_TITLE=`getprop "$1" name` +export PUBLISHED_DATE=`getprop "$1" published` +export DESCRIPTION=`getprop "$1" description` +export USERLOCAL1=`getprop "$1" userlocal1` +export USERLOCAL2=`getprop "$1" userlocal2` +# this only works when this script is called from pinopress script, as it inherits the required env variables. careful with this one, it's a bit hacky +export ARTICLE_URL="$SITEURL/$ARTICLE_PATH/$(echo $(basename "$1") | sed -e 's/\(.*\)\.html/\1\.md/')" diff --git a/pinopress b/pinopress index b457b13..3469586 100755 --- a/pinopress +++ b/pinopress @@ -22,25 +22,15 @@ ARTICLE_LIST := $(basename $(shell ls $(SRC_DIR))) # some helper functions define export_common export SITEURL="$(SITEURL)" + export ARTICLE_PATH="$(ARTICLE_PATH)" 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") + . ./$(MODULE_DIR)/md-header "$(SRC_DIR)/$$article_file" envsubst < $(TEMPLATE_DIR)/$(2) | sed -i "//r /dev/stdin" "$(1)" done endef