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 <igor@milhit.ch>
iGor milhit 2022-12-21 21:07:22 +01:00
parent a388b69b41
commit 5c2e673529
Signed by: igor
GPG Key ID: 692D97C3D0228A99
2 changed files with 30 additions and 2 deletions

View File

@ -6,10 +6,27 @@
.DEFAULT_GOAL:=help .DEFAULT_GOAL:=help
SHELL:=/bin/bash SHELL:=/bin/bash
# Get the output of the pandoc command
pandoc=$(shell command -v pandoc) pandoc=$(shell command -v pandoc)
# Get the version of pandoc
pandoc_version=$(shell pandoc --version | sed -e 's/.* // ; 1q') pandoc_version=$(shell pandoc --version | sed -e 's/.* // ; 1q')
# Get the output of the awk command
awk=$(shell command -v awk) 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 .PHONY: help deps
help: ## Display this help help: ## Display this help
@ -18,12 +35,17 @@ help: ## Display this help
deps: ## Check dependencies deps: ## Check dependencies
$(info Checking and getting dependencies) $(info Checking and getting dependencies)
ifeq ($(strip ($pandoc)),) ifeq ($(strip ($pandoc)),)
@echo "pandoc is required" @echo "pandoc is required and not installed"
else else
@echo "pandoc" $(pandoc_version) "is installed" @echo "pandoc" $(pandoc_version) "is installed"
endif endif
ifeq ($(strip ($awk)),) ifeq ($(strip ($awk)),)
@echo "awk is required" @echo "awk is required and not installed"
else else
@echo "awk is installed" @echo "awk is installed"
endif 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))

View File

@ -0,0 +1,6 @@
---
date: $date
id: $id
---