This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
59 lines (48 loc) · 1.46 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
.SHELLFLAGS := -eu -o pipefail -c
MAKEFLAGS += --warn-undefined-variables
SHELL = /bin/bash
.SUFFIXES:
# This makefile is for local development only and is not used by the live site
# it uses docker so you don't need to install anything
# @afirth 2019/07
# Create a new post:
# make new TITLE="my-post-title"
# Serve everything, including drafts, at localhost:1313
# make
DOCKER_IMAGE := klakegg/hugo:0.50
DOCKER_CMD := docker run --user $$(id -u):$$(id -g) --rm -it -v $(CURDIR):/src
DATE_STRING := $(shell date '+%Y/%m')
POST_PATH := post/$(DATE_STRING)/$(TITLE).md
.PHONY: all
all: open serve
# serve hugo on localhost:1313
.PHONY: serve
serve: check-docker
$(DOCKER_CMD) -p 1313:1313 $(DOCKER_IMAGE) server -D
# create a new blank post
.PHONY: new
new: check-docker check-title
$(DOCKER_CMD) $(DOCKER_IMAGE) new -v $(POST_PATH)
@printf "#Edit your post at created at\n\t./content/$(POST_PATH)\n"
# check docker is available
.PHONY: check-docker
check-docker:
@which docker 1>/dev/null || (echo Docker not found; exit 21)
# check title is set
.PHONY: check-title
check-title:
@[ "$(TITLE)" ] || (echo "TITLE is not set. make new TITLE=my-title"; exit 22)
# open browser (osx/linux) or print local browser link
.PHONY: open
open:
@case $$OSTYPE in \
linux-gnu) \
sleep 1 && xdg-open http://localhost:1313 & \
;; \
darwin|darwin19) \
sleep 1 && open http://localhost:1313 & \
;; \
*) \
sleep 1 && printf "# Open your browser to localhost:1313\n" \
;; \
esac