-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (72 loc) · 1.99 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#.SILENT:
.DEFAULT_GOAL := serve
.PHONY: help build serve new clean
COLOR_RESET=\033[0m
COLOR_INFO=\033[32m
COLOR_COMMENT=\033[33m
COLOR_ERROR=\033[31m
ifneq ($(shell [ -e .env ] && echo yes),yes)
$(shell cp .env.dist .env)
endif
include .env
ifndef PORT
override PORT="1313"
endif
ifndef BIND
override BIND="0.0.0.0"
endif
ifndef OUTPUT
override OUTPUT="$(PWD)/public/"
endif
ifndef SOURCE
override SOURCE="$(PWD)"
endif
HUGO := $(shell command -v hugo 2> /dev/null)
ifndef HUGO
DOCKER := $(shell command -v docker 2> /dev/null)
ifdef DOCKER
OUTPUT_HOST := $(OUTPUT)
HUGO=$(DOCKER) run --rm=true -i -v $(PWD):/src -v $(OUTPUT_HOST):/output -p $(PORT):$(PORT) jojomi/hugo /usr/local/sbin/hugo
override SOURCE="/src"
override OUTPUT="/output"
else
$(error "No hugo or docker in $(PATH), consider installing one of them")
endif
endif
## Outputs this help screen
help:
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n"
printf " make [target]\n\n"
printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n"
awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
## Pull gh-pages
pull: clean
git fetch origin gh-pages
git worktree add -B gh-pages public origin/gh-pages
## Build and serve static content
serve:
$(HUGO) server --source=$(SOURCE) --watch=true --bind=$(BIND) --port=$(PORT) --destination=$(OUTPUT)
## Build static content
build:
$(HUGO) --source=$(SOURCE) --destination=$(OUTPUT)
clean:
rm -rf public resources
git worktree prune
## Publish gh-pages
publish:
cd public && git add --all && git commit -m "Publishing to gh-pages" && cd ..
git push origin gh-pages
## Create new content file
new:
ifndef name
$(error "Missing 'name=[type/document_name].md'")
endif
$(HUGO) new $(name)