make: create a new file
- Creates a templates and a notes directory. - Creates a default template use 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 - Fixes #9. Co-Authored-by: iGor milhit <igor@milhit.ch>
parent
a388b69b41
commit
d011883a37
26
Makefile
26
Makefile
|
@ -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))
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
date: $date
|
||||||
|
id: $id
|
||||||
|
---
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue