From 5c2e6735295a7284e46cfc78a850884e241b9e2c Mon Sep 17 00:00:00 2001 From: iGor milhit Date: Wed, 21 Dec 2022 21:07:22 +0100 Subject: [PATCH] make: create a new file - Creates a templates and a notes directory. - Creates a default template used to create new files. It contains a minimal frontmatter with the creation date and an ID. - Adds the *new* recipe which creates a new file in the notes directory, based on the default template, replacing the creation date and ID variables with according values. - Updates the README file with the new recipe. - Improves the documentation of the code with comments. - Fixes #9. Co-Authored-by: iGor milhit --- Makefile | 26 ++++++++++++++++++++++++-- templates/default.md | 6 ++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 templates/default.md diff --git a/Makefile b/Makefile index 366854f..4084c06 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,27 @@ .DEFAULT_GOAL:=help SHELL:=/bin/bash +# Get the output of the pandoc command pandoc=$(shell command -v pandoc) +# Get the version of pandoc pandoc_version=$(shell pandoc --version | sed -e 's/.* // ; 1q') +# Get the output of the awk command awk=$(shell command -v awk) +# Get the datetime +now=$(shell date +%Y%m%d%H%M%S) +# Build the filename +filename=$(now).md + +# Export date and id as environment variable to replace the variables in the +# template file +export date:=$(shell date +%Y-%m-%dT%H:%M:%S%:z) +export id:=$(now) + +# Set the templates and notes directories +templates_directory=templates +notes_directory=notes + .PHONY: help deps help: ## Display this help @@ -18,12 +35,17 @@ help: ## Display this help deps: ## Check dependencies $(info Checking and getting dependencies) ifeq ($(strip ($pandoc)),) - @echo "pandoc is required" + @echo "pandoc is required and not installed" else @echo "pandoc" $(pandoc_version) "is installed" endif ifeq ($(strip ($awk)),) - @echo "awk is required" + @echo "awk is required and not installed" else @echo "awk is installed" endif + +new: ## Create a new file + $(info Creating a new file) + @ envsubst <$(templates_directory)/default.md >$(notes_directory)/$(filename) + $(info Your new file is $(notes_directory)/$(filename)) diff --git a/templates/default.md b/templates/default.md new file mode 100644 index 0000000..7240079 --- /dev/null +++ b/templates/default.md @@ -0,0 +1,6 @@ +--- +date: $date +id: $id +--- + +