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