Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 1 | PY?=python3 |
| 2 | PELICAN?=pelican |
| 3 | PELICANOPTS= |
| 4 | |
| 5 | BASEDIR=$(CURDIR) |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 6 | CONFFILE=$(BASEDIR)/pelicanconf.py |
| 7 | PUBLISHCONF=$(BASEDIR)/publishconf.py |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 8 | OUTPUTDIR=$(BASEDIR)/output |
| 9 | OUTPUTDIR_THEME=$(OUTPUTDIR)/theme |
| 10 | OUTPUTDIR_PHOTOS=$(OUTPUTDIR)/photos |
| 11 | OUTPUTDIR_VIDEOS=$(OUTPUTDIR)/videos |
| 12 | |
| 13 | ifeq ($(PELICAN_CONTENT),) |
| 14 | INPUTDIR=$(BASEDIR)/content |
| 15 | else |
| 16 | INPUTDIR=$(PELICAN_CONTENT) |
| 17 | endif |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 18 | |
| 19 | FTP_HOST=localhost |
| 20 | FTP_USER=anonymous |
| 21 | FTP_TARGET_DIR=/ |
| 22 | |
| 23 | SSH_HOST=localhost |
| 24 | SSH_PORT=22 |
| 25 | SSH_USER=root |
| 26 | SSH_TARGET_DIR=/var/www |
| 27 | |
| 28 | S3_BUCKET=my_s3_bucket |
| 29 | |
| 30 | CLOUDFILES_USERNAME=my_rackspace_username |
| 31 | CLOUDFILES_API_KEY=my_rackspace_api_key |
| 32 | CLOUDFILES_CONTAINER=my_cloudfiles_container |
| 33 | |
| 34 | DROPBOX_DIR=~/Dropbox/Public/ |
| 35 | |
| 36 | GITHUB_PAGES_BRANCH=gh-pages |
| 37 | |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 38 | INSTALLSUDO ?= 0 |
| 39 | ifeq ($(INSTALLSUDO),1) |
| 40 | SUDO := sudo -E |
| 41 | endif |
| 42 | INSTALLFLAGS := $(INSTALLFLAGS) -rXaA |
| 43 | INSTALLDIR ?= |
| 44 | # Copy the whole directory theme |
| 45 | INSTALLDIR_THEME ?= |
| 46 | # Copy contents only |
| 47 | INSTALLDIR_PHOTOS ?= |
| 48 | INSTALLDIR_VIDEOS ?= |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 49 | |
| 50 | DEBUG ?= 0 |
| 51 | ifeq ($(DEBUG), 1) |
| 52 | PELICANOPTS += -D |
| 53 | endif |
| 54 | |
| 55 | RELATIVE ?= 0 |
| 56 | ifeq ($(RELATIVE), 1) |
| 57 | PELICANOPTS += --relative-urls |
| 58 | endif |
| 59 | |
| 60 | help: |
| 61 | @echo 'Makefile for a pelican Web site ' |
| 62 | @echo ' ' |
| 63 | @echo 'Usage: ' |
| 64 | @echo ' make html (re)generate the web site ' |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 65 | @echo ' make clean-html remove all html files and folders ' |
| 66 | @echo ' make clean-theme remove output/theme ' |
| 67 | @echo ' make clean-photos remove output/photos ' |
| 68 | @echo ' make clean-videos remove output/videos ' |
| 69 | @echo ' make distclean remove output and __pycache__ ' |
| 70 | @echo ' make clean remove output folder ' |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 71 | @echo ' make regenerate regenerate files upon modification ' |
| 72 | @echo ' make publish generate using production settings ' |
| 73 | @echo ' make serve [PORT=8000] serve site at http://localhost:8000' |
| 74 | @echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 ' |
| 75 | @echo ' make devserver [PORT=8000] start/restart develop_server.sh ' |
| 76 | @echo ' make stopserver stop local server ' |
| 77 | @echo ' make ssh_upload upload the web site via SSH ' |
| 78 | @echo ' make rsync_upload upload the web site via rsync+ssh ' |
| 79 | @echo ' make dropbox_upload upload the web site via Dropbox ' |
| 80 | @echo ' make ftp_upload upload the web site via FTP ' |
| 81 | @echo ' make s3_upload upload the web site via S3 ' |
| 82 | @echo ' make cf_upload upload the web site via Cloud Files' |
| 83 | @echo ' make github upload the web site via gh-pages ' |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 84 | @echo ' make install-html copy *.html, html folders locally ' |
| 85 | @echo ' make install-theme copy output/theme locally ' |
| 86 | @echo ' make install-photos copy output/photos locally ' |
| 87 | @echo ' make install-videos copy output/videos locally ' |
| 88 | @echo ' make install copy output/* locally ' |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 89 | @echo ' ' |
| 90 | @echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html ' |
| 91 | @echo 'Set the RELATIVE variable to 1 to enable relative urls ' |
| 92 | @echo ' ' |
| 93 | |
| 94 | html: |
| 95 | $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) |
| 96 | |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 97 | clean-html: |
| 98 | find "$(OUTPUTDIR)" -type f -name *.html -delete |
| 99 | find "$(OUTPUTDIR)" -type d -empty -delete |
| 100 | |
| 101 | clean-theme: |
| 102 | [ ! -d "$(OUTPUTDIR_THEME)" ] || rm -rf $(OUTPUTDIR_THEME) |
| 103 | |
| 104 | clean-photos: |
| 105 | [ ! -d "$(OUTPUTDIR_PHOTOS)" ] || rm -rf $(OUTPUTDIR_PHOTOS) |
| 106 | |
| 107 | clean-videos: |
| 108 | [ ! -d "$(OUTPUTDIR_VIDEOS)" ] || rm -rf $(OUTPUTDIR_VIDEOS) |
| 109 | |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 110 | clean: |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 111 | [ ! -d "$(OUTPUTDIR)" ] || rm -rf $(OUTPUTDIR) |
| 112 | |
| 113 | distclean: clean |
| 114 | find $(BASEDIR) -type d -name "__pycache__" -exec rm -rf '{}' '+' |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 115 | |
| 116 | regenerate: |
| 117 | $(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) |
| 118 | |
| 119 | serve: |
| 120 | ifdef PORT |
| 121 | cd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT) |
| 122 | else |
| 123 | cd $(OUTPUTDIR) && $(PY) -m pelican.server |
| 124 | endif |
| 125 | |
| 126 | serve-global: |
| 127 | ifdef SERVER |
| 128 | cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER) |
| 129 | else |
| 130 | cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0 |
| 131 | endif |
| 132 | |
| 133 | |
| 134 | devserver: |
| 135 | ifdef PORT |
| 136 | $(BASEDIR)/develop_server.sh restart $(PORT) |
| 137 | else |
| 138 | $(BASEDIR)/develop_server.sh restart |
| 139 | endif |
| 140 | |
| 141 | stopserver: |
| 142 | $(BASEDIR)/develop_server.sh stop |
| 143 | @echo 'Stopped Pelican and SimpleHTTPServer processes running in background.' |
| 144 | |
| 145 | publish: |
| 146 | $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS) |
| 147 | |
| 148 | ssh_upload: publish |
| 149 | scp -P $(SSH_PORT) -r $(OUTPUTDIR)/* $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) |
| 150 | |
| 151 | rsync_upload: publish |
| 152 | rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude |
| 153 | |
| 154 | dropbox_upload: publish |
| 155 | cp -r $(OUTPUTDIR)/* $(DROPBOX_DIR) |
| 156 | |
| 157 | ftp_upload: publish |
| 158 | lftp ftp://$(FTP_USER)@$(FTP_HOST) -e "mirror -R $(OUTPUTDIR) $(FTP_TARGET_DIR) ; quit" |
| 159 | |
| 160 | s3_upload: publish |
| 161 | s3cmd sync $(OUTPUTDIR)/ s3://$(S3_BUCKET) --acl-public --delete-removed --guess-mime-type --no-mime-magic --no-preserve |
| 162 | |
| 163 | cf_upload: publish |
| 164 | cd $(OUTPUTDIR) && swift -v -A https://auth.api.rackspacecloud.com/v1.0 -U $(CLOUDFILES_USERNAME) -K $(CLOUDFILES_API_KEY) upload -c $(CLOUDFILES_CONTAINER) . |
| 165 | |
| 166 | github: publish |
| 167 | ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR) |
| 168 | git push origin $(GITHUB_PAGES_BRANCH) |
| 169 | |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 170 | install-html: |
| 171 | [ -d "$(OUTPUTDIR)" ] && [ -d "$(INSTALLDIR)" ] && \ |
| 172 | $(SUDO) rsync $(INSTALLFLAGS) \ |
| 173 | --exclude=$(notdir $(OUTPUTDIR_THEME)) \ |
| 174 | --exclude=$(notdir $(OUTPUTDIR_PHOTOS)) \ |
| 175 | --exclude=$(notdir $(OUTPUTDIR_VIDEOS)) \ |
| 176 | $(OUTPUTDIR)/* $(INSTALLDIR) |
| 177 | |
| 178 | install-theme: |
| 179 | [ -d "$(OUTPUTDIR_THEME)" ] && [ -d "$(INSTALLDIR_THEME)" ] && \ |
| 180 | $(SUDO) rsync $(INSTALLFLAGS) $(OUTPUTDIR_THEME) $(INSTALLDIR_THEME)/ |
| 181 | |
| 182 | install-photos: |
| 183 | [ ! -d "$(OUTPUTDIR_PHOTOS)" ] && { echo "Nothing to do for: install-photos"; \ |
| 184 | exit 0; } || [ -d "$(INSTALLDIR_PHOTOS)" ] && \ |
| 185 | $(SUDO) rsync $(INSTALLFLAGS) $(OUTPUTDIR_PHOTOS)/ $(INSTALLDIR_PHOTOS) |
| 186 | |
| 187 | install-videos: |
| 188 | [ ! -d "$(OUTPUTDIR_VIDEOS)" ] && { echo "Nothing to do for: install-videos"; \ |
| 189 | exit 0; } || [ -d "$(INSTALLDIR_VIDEOS)" ] && \ |
| 190 | $(SUDO) rsync $(INSTALLFLAGS) $(OUTPUTDIR_VIDEOS)/ $(INSTALLDIR_VIDEOS) |
| 191 | |
| 192 | install: install-html install-theme install-photos install-videos |
Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame] | 193 | |
| 194 | |
Luigi Santivetti | 6ce0e13 | 2020-10-07 23:28:00 +0100 | [diff] [blame] | 195 | .PHONY: html help clean clean-html clean-theme clean-photos regenerate serve serve-global devserver stopserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github install install-html install-theme install-photos |