-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
85 lines (75 loc) · 2.11 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
85
# Configuration
HUGO_VERSION ?= 0.31.1
HUGO_THEME ?= ""
GIT_COMMITTER_NAME ?= autohugo
GIT_COMMITTER_EMAIL ?= [email protected]
# System
OS = 64bit
ifeq ($(OS),Windows_NT)
ARCH = Windows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
ARCH = Linux
endif
ifeq ($(UNAME_S),Darwin)
ARCH = Darwin
endif
endif
# Environment
SHELL := /bin/bash
BASE_PATH := $(shell pwd)
PUBLIC_PATH := $(BASE_PATH)/public
THEMES_PATH := $(BASE_PATH)/themes
THEME_NAME := $(shell basename $(HUGO_THEME))
THEME_PATH := $(THEMES_PATH)/$(THEME_NAME)
HUGO_PATH := $(BASE_PATH)/.hugo
HUGO_URL = github.com/gohugoio/hugo
HUGO_NAME := hugo_$(HUGO_VERSION)_$(ARCH)-$(OS)
# Tools
CURL = curl -L
HUGO = $(HUGO_PATH)/hugo
MKDIR = mkdir -p
GIT = git
# Rules
all: build
init:
@if [ "$(HUGO_THEME)" == "" ]; then \
echo "ERROR! Please set the env variable 'HUGO_THEME' (http://mcuadros.github.io/autohugo/documentation/working-with-autohugo/)"; \
exit 1; \
fi;
dependencies: init
@if [[ ! -f $(HUGO) ]]; then \
$(MKDIR) $(HUGO_PATH); \
cd $(HUGO_PATH); \
ext="zip"; \
if [ "$(ARCH)" == "Linux" ]; then ext="tar.gz"; fi; \
file="hugo.$${ext}"; \
$(CURL) https://$(HUGO_URL)/releases/download/v$(HUGO_VERSION)/$(HUGO_NAME).$${ext} -o $${file}; \
if [ "$(ARCH)" == "Linux" ]; then tar -xvzf $${file}; else unzip $${file}; fi; \
fi;
@if [[ ! -d $(THEME_PATH) ]]; then \
$(MKDIR) $(THEMES_PATH); \
cd $(THEMES_PATH); \
$(GIT) clone $(HUGO_THEME) $(THEME_NAME); \
fi;
build: dependencies
$(HUGO) -t $(THEME_NAME)
server: build
$(HUGO) server -t $(THEME_NAME) -D -w
publish: init
@if [ "$(CI)" == "" ]; then \
echo "ERROR! Publish should be called only on CircleCI"; \
exit 1; \
fi;
cp -rf $(THEME_PATH)/static/* $(PUBLIC_PATH)/
rm .gitignore
$(GIT) config user.email "$(GIT_COMMITTER_EMAIL)"
$(GIT) config user.name "$(GIT_COMMITTER_NAME)"
$(GIT) add -A
$(GIT) commit -m "updating site [ci skip]"
$(GIT) push origin :gh-pages || true
$(GIT) subtree push --prefix=public [email protected]:$(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME).git gh-pages
clean:
rm -rf $(HUGO_PATH)
rm -rf $(THEME_PATH)