pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

commit 0bc0f46627ce6a1045e30f709889dea055ff9573
parent 81de58ed87338fe3829172465ec0a48479d51ada
Author: pyratebeard <root@pyratebeard.net>
Date:   Wed, 21 Sep 2022 23:13:28 +0100

make

scripts for starting draft and pu lishing. preview is still wip. makefile uses funky ifeq conditions to pass args on cli

Diffstat:
AMakefile | 29+++++++++++++++++++++++++++++
Ascripts/draft | 16++++++++++++++++
Ascripts/preview | 3+++
Ascripts/publish | 19+++++++++++++++++++
4 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,29 @@ +#TITLE := $(shell git branch --show-current) +# https://stackoverflow.com/a/14061796 +# If the first argument is "draft" +ifeq (draft,$(firstword $(MAKECMDGOALS))) + # use the rest as arguments for "draft" + DRAFT_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + # ...and turn them into do-nothing targets + $(eval $(DRAFT_ARGS):;@:) +else (preview,$(firstword $(MAKECMDGOALS))) + VIEW_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + $(eval $(VIEW_ARGS):;@:) +else (publish,$(firstword $(MAKECMDGOALS))) + PUB_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + $(eval $(PUB_ARGS):;@:) +endif + +prog: # ... + # ... + +.PHONY: draft preview publish + +draft : prog + scripts/draft $(DRAFT_ARGS) + +preview : prog + scripts/preview $(VIEW_ARGS) + +publish : prog + scripts/publish $(PUB_ARGS) diff --git a/scripts/draft b/scripts/draft @@ -0,0 +1,16 @@ +#!/bin/sh + +TITLE=$1 +POST="entry/${TITLE}.md" + +git branch | grep ${TITLE} && \ + git checkout ${TITLE} || \ + git checkout -b ${TITLE} + +[ -f "${POST}" ] || touch "${POST}" + +vim "${POST}" + +git add "${POST}" + +git commit -S -m "${TITLE}" diff --git a/scripts/preview b/scripts/preview @@ -0,0 +1,3 @@ +#!/bin/sh + +echo preview diff --git a/scripts/publish b/scripts/publish @@ -0,0 +1,19 @@ +#!/bin/sh + +TITLE=$1 +POST="entry/${TITLE}.md" +PUBLISH="entry/$(date +%Y%m%d)-${TITLE}.md" + +git branch | grep ${TITLE} && \ + git checkout ${TITLE} || \ + git checkout -b ${TITLE} + +git mv "${POST}" "${PUBLISH}" + +git commit -S -m "publish ${TITLE}" + +git checkout main + +git merge "${TITLE}" + +git push