mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
pelican-quickstart: switch to jinja2
- Use the jinja2 templating language for Makefile, fabfile, pelicanconf, publishconf, and develop-server.sh - Add logic in pelican_quickstart.py - Let jinja2 handle opening and reading template files - Remove thus unused functions for string.Template
This commit is contained in:
parent
34103cd5dd
commit
6d46bf4257
11 changed files with 465 additions and 420 deletions
|
|
@ -6,9 +6,10 @@ import argparse
|
||||||
import codecs
|
import codecs
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
import string
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -30,6 +31,11 @@ else:
|
||||||
|
|
||||||
_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||||
"templates")
|
"templates")
|
||||||
|
_jinja_env = Environment(
|
||||||
|
loader=FileSystemLoader(_TEMPLATES_DIR),
|
||||||
|
trim_blocks=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
_GITHUB_PAGES_BRANCHES = {
|
_GITHUB_PAGES_BRANCHES = {
|
||||||
'personal': 'master',
|
'personal': 'master',
|
||||||
|
|
@ -99,20 +105,6 @@ def decoding_strings(f):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def get_template(name, as_encoding='utf-8'):
|
|
||||||
template = os.path.join(_TEMPLATES_DIR, "{0}.in".format(name))
|
|
||||||
|
|
||||||
if not os.path.isfile(template):
|
|
||||||
raise RuntimeError("Cannot open {0}".format(template))
|
|
||||||
|
|
||||||
with codecs.open(template, 'r', as_encoding) as fd:
|
|
||||||
line = fd.readline()
|
|
||||||
while line:
|
|
||||||
yield line
|
|
||||||
line = fd.readline()
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
|
|
||||||
@decoding_strings
|
@decoding_strings
|
||||||
def ask(question, answer=str_compat, default=None, length=None):
|
def ask(question, answer=str_compat, default=None, length=None):
|
||||||
if answer == str_compat:
|
if answer == str_compat:
|
||||||
|
|
@ -273,6 +265,7 @@ needed by Pelican.
|
||||||
if automation:
|
if automation:
|
||||||
if ask('Do you want to upload your website using FTP?',
|
if ask('Do you want to upload your website using FTP?',
|
||||||
answer=bool, default=False):
|
answer=bool, default=False):
|
||||||
|
CONF['ftp'] = True,
|
||||||
CONF['ftp_host'] = ask('What is the hostname of your FTP server?',
|
CONF['ftp_host'] = ask('What is the hostname of your FTP server?',
|
||||||
str_compat, CONF['ftp_host'])
|
str_compat, CONF['ftp_host'])
|
||||||
CONF['ftp_user'] = ask('What is your username on that server?',
|
CONF['ftp_user'] = ask('What is your username on that server?',
|
||||||
|
|
@ -282,6 +275,7 @@ needed by Pelican.
|
||||||
str_compat, CONF['ftp_target_dir'])
|
str_compat, CONF['ftp_target_dir'])
|
||||||
if ask('Do you want to upload your website using SSH?',
|
if ask('Do you want to upload your website using SSH?',
|
||||||
answer=bool, default=False):
|
answer=bool, default=False):
|
||||||
|
CONF['ssh'] = True,
|
||||||
CONF['ssh_host'] = ask('What is the hostname of your SSH server?',
|
CONF['ssh_host'] = ask('What is the hostname of your SSH server?',
|
||||||
str_compat, CONF['ssh_host'])
|
str_compat, CONF['ssh_host'])
|
||||||
CONF['ssh_port'] = ask('What is the port of your SSH server?',
|
CONF['ssh_port'] = ask('What is the port of your SSH server?',
|
||||||
|
|
@ -294,16 +288,19 @@ needed by Pelican.
|
||||||
|
|
||||||
if ask('Do you want to upload your website using Dropbox?',
|
if ask('Do you want to upload your website using Dropbox?',
|
||||||
answer=bool, default=False):
|
answer=bool, default=False):
|
||||||
|
CONF['dropbox'] = True,
|
||||||
CONF['dropbox_dir'] = ask('Where is your Dropbox directory?',
|
CONF['dropbox_dir'] = ask('Where is your Dropbox directory?',
|
||||||
str_compat, CONF['dropbox_dir'])
|
str_compat, CONF['dropbox_dir'])
|
||||||
|
|
||||||
if ask('Do you want to upload your website using S3?',
|
if ask('Do you want to upload your website using S3?',
|
||||||
answer=bool, default=False):
|
answer=bool, default=False):
|
||||||
|
CONF['s3'] = True,
|
||||||
CONF['s3_bucket'] = ask('What is the name of your S3 bucket?',
|
CONF['s3_bucket'] = ask('What is the name of your S3 bucket?',
|
||||||
str_compat, CONF['s3_bucket'])
|
str_compat, CONF['s3_bucket'])
|
||||||
|
|
||||||
if ask('Do you want to upload your website using '
|
if ask('Do you want to upload your website using '
|
||||||
'Rackspace Cloud Files?', answer=bool, default=False):
|
'Rackspace Cloud Files?', answer=bool, default=False):
|
||||||
|
CONF['cloudfiles'] = True,
|
||||||
CONF['cloudfiles_username'] = ask('What is your Rackspace '
|
CONF['cloudfiles_username'] = ask('What is your Rackspace '
|
||||||
'Cloud username?', str_compat,
|
'Cloud username?', str_compat,
|
||||||
CONF['cloudfiles_username'])
|
CONF['cloudfiles_username'])
|
||||||
|
|
@ -317,6 +314,7 @@ needed by Pelican.
|
||||||
|
|
||||||
if ask('Do you want to upload your website using GitHub Pages?',
|
if ask('Do you want to upload your website using GitHub Pages?',
|
||||||
answer=bool, default=False):
|
answer=bool, default=False):
|
||||||
|
CONF['github'] = True,
|
||||||
if ask('Is this your personal page (username.github.io)?',
|
if ask('Is this your personal page (username.github.io)?',
|
||||||
answer=bool, default=False):
|
answer=bool, default=False):
|
||||||
CONF['github_pages_branch'] = \
|
CONF['github_pages_branch'] = \
|
||||||
|
|
@ -342,9 +340,8 @@ needed by Pelican.
|
||||||
for key, value in CONF.items():
|
for key, value in CONF.items():
|
||||||
conf_python[key] = repr(value)
|
conf_python[key] = repr(value)
|
||||||
|
|
||||||
for line in get_template('pelicanconf.py'):
|
_template = _jinja_env.get_template('pelicanconf.py.jinja2')
|
||||||
template = string.Template(line)
|
fd.write(_template.render(**conf_python))
|
||||||
fd.write(template.safe_substitute(conf_python))
|
|
||||||
fd.close()
|
fd.close()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print('Error: {0}'.format(e))
|
print('Error: {0}'.format(e))
|
||||||
|
|
@ -352,9 +349,8 @@ needed by Pelican.
|
||||||
try:
|
try:
|
||||||
with codecs.open(os.path.join(CONF['basedir'], 'publishconf.py'),
|
with codecs.open(os.path.join(CONF['basedir'], 'publishconf.py'),
|
||||||
'w', 'utf-8') as fd:
|
'w', 'utf-8') as fd:
|
||||||
for line in get_template('publishconf.py'):
|
_template = _jinja_env.get_template('publishconf.py.jinja2')
|
||||||
template = string.Template(line)
|
fd.write(_template.render(**CONF))
|
||||||
fd.write(template.safe_substitute(CONF))
|
|
||||||
fd.close()
|
fd.close()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print('Error: {0}'.format(e))
|
print('Error: {0}'.format(e))
|
||||||
|
|
@ -363,25 +359,19 @@ needed by Pelican.
|
||||||
try:
|
try:
|
||||||
with codecs.open(os.path.join(CONF['basedir'], 'fabfile.py'),
|
with codecs.open(os.path.join(CONF['basedir'], 'fabfile.py'),
|
||||||
'w', 'utf-8') as fd:
|
'w', 'utf-8') as fd:
|
||||||
for line in get_template('fabfile.py'):
|
_template = _jinja_env.get_template('fabfile.py.jinja2')
|
||||||
template = string.Template(line)
|
fd.write(_template.render(**CONF))
|
||||||
fd.write(template.safe_substitute(CONF))
|
|
||||||
fd.close()
|
fd.close()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print('Error: {0}'.format(e))
|
print('Error: {0}'.format(e))
|
||||||
try:
|
try:
|
||||||
with codecs.open(os.path.join(CONF['basedir'], 'Makefile'),
|
with codecs.open(os.path.join(CONF['basedir'], 'Makefile'),
|
||||||
'w', 'utf-8') as fd:
|
'w', 'utf-8') as fd:
|
||||||
mkfile_template_name = 'Makefile'
|
py_v = 'python'
|
||||||
py_v = 'PY?=python'
|
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
py_v = 'PY?=python3'
|
py_v = 'python3'
|
||||||
template = string.Template(py_v)
|
_template = _jinja_env.get_template('Makefile.jinja2')
|
||||||
fd.write(template.safe_substitute(CONF))
|
fd.write(_template.render(py_v=py_v, **CONF))
|
||||||
fd.write('\n')
|
|
||||||
for line in get_template(mkfile_template_name):
|
|
||||||
template = string.Template(line)
|
|
||||||
fd.write(template.safe_substitute(CONF))
|
|
||||||
fd.close()
|
fd.close()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print('Error: {0}'.format(e))
|
print('Error: {0}'.format(e))
|
||||||
|
|
@ -396,14 +386,11 @@ needed by Pelican.
|
||||||
with codecs.open(os.path.join(CONF['basedir'],
|
with codecs.open(os.path.join(CONF['basedir'],
|
||||||
'develop_server.sh'),
|
'develop_server.sh'),
|
||||||
'w', 'utf-8') as fd:
|
'w', 'utf-8') as fd:
|
||||||
lines = list(get_template('develop_server.sh'))
|
py_v = '${PY:-python}'
|
||||||
py_v = 'PY=${PY:-python}\n'
|
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
py_v = 'PY=${PY:-python3}\n'
|
py_v = '${PY:-python3}'
|
||||||
lines = lines[:4] + [py_v] + lines[4:]
|
_template = _jinja_env.get_template('develop_server.sh.jinja2')
|
||||||
for line in lines:
|
fd.write(_template.render(py_v=py_v, **conf_shell))
|
||||||
template = string.Template(line)
|
|
||||||
fd.write(template.safe_substitute(conf_shell))
|
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
# mode 0o755
|
# mode 0o755
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,44 @@
|
||||||
PELICAN?=$pelican
|
PY?={{py_v}}
|
||||||
PELICANOPTS=$pelicanopts
|
PELICAN?={{pelican}}
|
||||||
|
PELICANOPTS={{pelicanopts}}
|
||||||
|
|
||||||
BASEDIR=$$(CURDIR)
|
BASEDIR=$(CURDIR)
|
||||||
INPUTDIR=$$(BASEDIR)/content
|
INPUTDIR=$(BASEDIR)/content
|
||||||
OUTPUTDIR=$$(BASEDIR)/output
|
OUTPUTDIR=$(BASEDIR)/output
|
||||||
CONFFILE=$$(BASEDIR)/pelicanconf.py
|
CONFFILE=$(BASEDIR)/pelicanconf.py
|
||||||
PUBLISHCONF=$$(BASEDIR)/publishconf.py
|
PUBLISHCONF=$(BASEDIR)/publishconf.py
|
||||||
|
|
||||||
FTP_HOST=$ftp_host
|
{% if ftp %}
|
||||||
FTP_USER=$ftp_user
|
FTP_HOST={{ftp_host}}
|
||||||
FTP_TARGET_DIR=$ftp_target_dir
|
FTP_USER={{ftp_user}}
|
||||||
|
FTP_TARGET_DIR={{ftp_target_dir}}
|
||||||
|
|
||||||
SSH_HOST=$ssh_host
|
{% endif %}
|
||||||
SSH_PORT=$ssh_port
|
{% if ssh %}
|
||||||
SSH_USER=$ssh_user
|
SSH_HOST={{ssh_host}}
|
||||||
SSH_TARGET_DIR=$ssh_target_dir
|
SSH_PORT={{ssh_port}}
|
||||||
|
SSH_USER={{ssh_user}}
|
||||||
|
SSH_TARGET_DIR={{ssh_target_dir}}
|
||||||
|
|
||||||
S3_BUCKET=$s3_bucket
|
{% endif %}
|
||||||
|
{% if s3 %}
|
||||||
|
S3_BUCKET={{s3_bucket}}
|
||||||
|
|
||||||
CLOUDFILES_USERNAME=$cloudfiles_username
|
{% endif %}
|
||||||
CLOUDFILES_API_KEY=$cloudfiles_api_key
|
{% if cloudfiles %}
|
||||||
CLOUDFILES_CONTAINER=$cloudfiles_container
|
CLOUDFILES_USERNAME={{cloudfiles_username}}
|
||||||
|
CLOUDFILES_API_KEY={{cloudfiles_api_key}}
|
||||||
|
CLOUDFILES_CONTAINER={{cloudfiles_container}}
|
||||||
|
|
||||||
DROPBOX_DIR=$dropbox_dir
|
{% endif %}
|
||||||
|
{% if dropbox %}
|
||||||
|
DROPBOX_DIR={{dropbox_dir}}
|
||||||
|
|
||||||
GITHUB_PAGES_BRANCH=$github_pages_branch
|
{% endif %}
|
||||||
|
{% if github %}
|
||||||
|
GITHUB_PAGES_BRANCH={{github_pages_branch}}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
DEBUG ?= 0
|
DEBUG ?= 0
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
|
|
@ -48,47 +62,59 @@ help:
|
||||||
@echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
|
@echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
|
||||||
@echo ' make devserver [PORT=8000] start/restart develop_server.sh '
|
@echo ' make devserver [PORT=8000] start/restart develop_server.sh '
|
||||||
@echo ' make stopserver stop local server '
|
@echo ' make stopserver stop local server '
|
||||||
|
{% if ssh %}
|
||||||
@echo ' make ssh_upload upload the web site via SSH '
|
@echo ' make ssh_upload upload the web site via SSH '
|
||||||
@echo ' make rsync_upload upload the web site via rsync+ssh '
|
@echo ' make rsync_upload upload the web site via rsync+ssh '
|
||||||
|
{% endif %}
|
||||||
|
{% if dropbox %}
|
||||||
@echo ' make dropbox_upload upload the web site via Dropbox '
|
@echo ' make dropbox_upload upload the web site via Dropbox '
|
||||||
|
{% endif %}
|
||||||
|
{% if ftp %}
|
||||||
@echo ' make ftp_upload upload the web site via FTP '
|
@echo ' make ftp_upload upload the web site via FTP '
|
||||||
|
{% endif %}
|
||||||
|
{% if s3 %}
|
||||||
@echo ' make s3_upload upload the web site via S3 '
|
@echo ' make s3_upload upload the web site via S3 '
|
||||||
|
{% endif %}
|
||||||
|
{% if cloudfiles %}
|
||||||
@echo ' make cf_upload upload the web site via Cloud Files'
|
@echo ' make cf_upload upload the web site via Cloud Files'
|
||||||
|
{% endif %}
|
||||||
|
{% if github %}
|
||||||
@echo ' make github upload the web site via gh-pages '
|
@echo ' make github upload the web site via gh-pages '
|
||||||
|
{% endif %}
|
||||||
@echo ' '
|
@echo ' '
|
||||||
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
|
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
|
||||||
@echo 'Set the RELATIVE variable to 1 to enable relative urls '
|
@echo 'Set the RELATIVE variable to 1 to enable relative urls '
|
||||||
@echo ' '
|
@echo ' '
|
||||||
|
|
||||||
html:
|
html:
|
||||||
$$(PELICAN) $$(INPUTDIR) -o $$(OUTPUTDIR) -s $$(CONFFILE) $$(PELICANOPTS)
|
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
[ ! -d $$(OUTPUTDIR) ] || rm -rf $$(OUTPUTDIR)
|
[ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)
|
||||||
|
|
||||||
regenerate:
|
regenerate:
|
||||||
$$(PELICAN) -r $$(INPUTDIR) -o $$(OUTPUTDIR) -s $$(CONFFILE) $$(PELICANOPTS)
|
$(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
|
||||||
|
|
||||||
serve:
|
serve:
|
||||||
ifdef PORT
|
ifdef PORT
|
||||||
cd $$(OUTPUTDIR) && $(PY) -m pelican.server $$(PORT)
|
cd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT)
|
||||||
else
|
else
|
||||||
cd $$(OUTPUTDIR) && $(PY) -m pelican.server
|
cd $(OUTPUTDIR) && $(PY) -m pelican.server
|
||||||
endif
|
endif
|
||||||
|
|
||||||
serve-global:
|
serve-global:
|
||||||
ifdef SERVER
|
ifdef SERVER
|
||||||
cd $$(OUTPUTDIR) && $(PY) -m pelican.server 80 $$(SERVER)
|
cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER)
|
||||||
else
|
else
|
||||||
cd $$(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0
|
cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
devserver:
|
devserver:
|
||||||
ifdef PORT
|
ifdef PORT
|
||||||
$$(BASEDIR)/develop_server.sh restart $$(PORT)
|
$(BASEDIR)/develop_server.sh restart $(PORT)
|
||||||
else
|
else
|
||||||
$$(BASEDIR)/develop_server.sh restart
|
$(BASEDIR)/develop_server.sh restart
|
||||||
endif
|
endif
|
||||||
|
|
||||||
stopserver:
|
stopserver:
|
||||||
|
|
@ -96,28 +122,49 @@ stopserver:
|
||||||
@echo 'Stopped Pelican and SimpleHTTPServer processes running in background.'
|
@echo 'Stopped Pelican and SimpleHTTPServer processes running in background.'
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
$$(PELICAN) $$(INPUTDIR) -o $$(OUTPUTDIR) -s $$(PUBLISHCONF) $$(PELICANOPTS)
|
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)
|
||||||
|
|
||||||
|
{% set upload = [] %}
|
||||||
|
{% if ssh %}
|
||||||
|
{% set upload = upload + ["ssh_upload"] %}
|
||||||
ssh_upload: publish
|
ssh_upload: publish
|
||||||
scp -P $$(SSH_PORT) -r $$(OUTPUTDIR)/* $$(SSH_USER)@$$(SSH_HOST):$$(SSH_TARGET_DIR)
|
scp -P $(SSH_PORT) -r $(OUTPUTDIR)/* $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)
|
||||||
|
|
||||||
|
{%- set upload = upload + ["rsync_upload"] -%}
|
||||||
rsync_upload: publish
|
rsync_upload: publish
|
||||||
rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --cvs-exclude --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)
|
rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --cvs-exclude --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if dropbox %}
|
||||||
|
{% set upload = upload + ["dropbox_upload"] %}
|
||||||
dropbox_upload: publish
|
dropbox_upload: publish
|
||||||
cp -r $$(OUTPUTDIR)/* $$(DROPBOX_DIR)
|
cp -r $(OUTPUTDIR)/* $(DROPBOX_DIR)
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if ftp %}
|
||||||
|
{% set upload = upload + ["ftp_upload"] %}
|
||||||
ftp_upload: publish
|
ftp_upload: publish
|
||||||
lftp ftp://$$(FTP_USER)@$$(FTP_HOST) -e "mirror -R $$(OUTPUTDIR) $$(FTP_TARGET_DIR) ; quit"
|
lftp ftp://$(FTP_USER)@$(FTP_HOST) -e "mirror -R $(OUTPUTDIR) $(FTP_TARGET_DIR) ; quit"
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if s3 %}
|
||||||
|
{% set upload = upload + ["s3_upload"] %}
|
||||||
s3_upload: publish
|
s3_upload: publish
|
||||||
aws s3 sync $(OUTPUTDIR)/ s3://$(S3_BUCKET) --acl public-read --delete
|
aws s3 sync $(OUTPUTDIR)/ s3://$(S3_BUCKET) --acl public-read --delete
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if cloudfiles %}
|
||||||
|
{% set upload = upload + ["cf_upload"] %}
|
||||||
cf_upload: publish
|
cf_upload: publish
|
||||||
cd $(OUTPUTDIR) && swift -v -A https://auth.api.rackspacecloud.com/v1.0 -U $(CLOUDFILES_USERNAME) -K $(CLOUDFILES_API_KEY) upload -c $(CLOUDFILES_CONTAINER) .
|
cd $(OUTPUTDIR) && swift -v -A https://auth.api.rackspacecloud.com/v1.0 -U $(CLOUDFILES_USERNAME) -K $(CLOUDFILES_API_KEY) upload -c $(CLOUDFILES_CONTAINER) .
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if github %}
|
||||||
|
{% set upload = upload + ["github"] %}
|
||||||
github: publish
|
github: publish
|
||||||
ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $$(OUTPUTDIR)
|
ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR)
|
||||||
git push origin $(GITHUB_PAGES_BRANCH)
|
git push origin $(GITHUB_PAGES_BRANCH)
|
||||||
|
|
||||||
.PHONY: html help clean regenerate serve serve-global devserver stopserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github
|
{% endif %}
|
||||||
|
|
||||||
|
.PHONY: html help clean regenerate serve serve-global devserver stopserver publish {{ upload|join(" ") }}
|
||||||
|
|
@ -2,23 +2,24 @@
|
||||||
##
|
##
|
||||||
# This section should match your Makefile
|
# This section should match your Makefile
|
||||||
##
|
##
|
||||||
PELICAN=$${PELICAN:-$pelican}
|
PY={{py_v}}
|
||||||
PELICANOPTS=$pelicanopts
|
PELICAN=${PELICAN:-pelican}
|
||||||
|
PELICANOPTS={{pelicanopts}}
|
||||||
|
|
||||||
BASEDIR=$$(pwd)
|
BASEDIR=$(pwd)
|
||||||
INPUTDIR=$$BASEDIR/content
|
INPUTDIR=$BASEDIR/content
|
||||||
OUTPUTDIR=$$BASEDIR/output
|
OUTPUTDIR=$BASEDIR/output
|
||||||
CONFFILE=$$BASEDIR/pelicanconf.py
|
CONFFILE=$BASEDIR/pelicanconf.py
|
||||||
|
|
||||||
###
|
###
|
||||||
# Don't change stuff below here unless you are sure
|
# Don't change stuff below here unless you are sure
|
||||||
###
|
###
|
||||||
|
|
||||||
SRV_PID=$$BASEDIR/srv.pid
|
SRV_PID=$BASEDIR/srv.pid
|
||||||
PELICAN_PID=$$BASEDIR/pelican.pid
|
PELICAN_PID=$BASEDIR/pelican.pid
|
||||||
|
|
||||||
function usage(){
|
function usage(){
|
||||||
echo "usage: $$0 (stop) (start) (restart) [port]"
|
echo "usage: $0 (stop) (start) (restart) [port]"
|
||||||
echo "This starts Pelican in debug and reload mode and then launches"
|
echo "This starts Pelican in debug and reload mode and then launches"
|
||||||
echo "an HTTP server to help site development. It doesn't read"
|
echo "an HTTP server to help site development. It doesn't read"
|
||||||
echo "your Pelican settings, so if you edit any paths in your Makefile"
|
echo "your Pelican settings, so if you edit any paths in your Makefile"
|
||||||
|
|
@ -27,55 +28,55 @@ function usage(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function alive() {
|
function alive() {
|
||||||
kill -0 $$1 >/dev/null 2>&1
|
kill -0 $1 >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
function shut_down(){
|
function shut_down(){
|
||||||
PID=$$(cat $$SRV_PID)
|
PID=$(cat $SRV_PID)
|
||||||
if [[ $$? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
if alive $PID; then
|
if alive $PID; then
|
||||||
echo "Stopping HTTP server"
|
echo "Stopping HTTP server"
|
||||||
kill $$PID
|
kill $PID
|
||||||
else
|
else
|
||||||
echo "Stale PID, deleting"
|
echo "Stale PID, deleting"
|
||||||
fi
|
fi
|
||||||
rm $$SRV_PID
|
rm $SRV_PID
|
||||||
else
|
else
|
||||||
echo "HTTP server PIDFile not found"
|
echo "HTTP server PIDFile not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PID=$$(cat $$PELICAN_PID)
|
PID=$(cat $PELICAN_PID)
|
||||||
if [[ $$? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
if alive $$PID; then
|
if alive $PID; then
|
||||||
echo "Killing Pelican"
|
echo "Killing Pelican"
|
||||||
kill $$PID
|
kill $PID
|
||||||
else
|
else
|
||||||
echo "Stale PID, deleting"
|
echo "Stale PID, deleting"
|
||||||
fi
|
fi
|
||||||
rm $$PELICAN_PID
|
rm $PELICAN_PID
|
||||||
else
|
else
|
||||||
echo "Pelican PIDFile not found"
|
echo "Pelican PIDFile not found"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_up(){
|
function start_up(){
|
||||||
local port=$$1
|
local port=$1
|
||||||
echo "Starting up Pelican and HTTP server"
|
echo "Starting up Pelican and HTTP server"
|
||||||
shift
|
shift
|
||||||
$$PELICAN --debug --autoreload -r $$INPUTDIR -o $$OUTPUTDIR -s $$CONFFILE $$PELICANOPTS &
|
$PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
|
||||||
pelican_pid=$$!
|
pelican_pid=$!
|
||||||
echo $$pelican_pid > $$PELICAN_PID
|
echo $pelican_pid > $PELICAN_PID
|
||||||
mkdir -p $$OUTPUTDIR && cd $$OUTPUTDIR
|
mkdir -p $OUTPUTDIR && cd $OUTPUTDIR
|
||||||
$PY -m pelican.server $$port &
|
$PY -m pelican.server $port &
|
||||||
srv_pid=$$!
|
srv_pid=$!
|
||||||
echo $$srv_pid > $$SRV_PID
|
echo $srv_pid > $SRV_PID
|
||||||
cd $$BASEDIR
|
cd $BASEDIR
|
||||||
sleep 1
|
sleep 1
|
||||||
if ! alive $$pelican_pid ; then
|
if ! alive $pelican_pid ; then
|
||||||
echo "Pelican didn't start. Is the Pelican package installed?"
|
echo "Pelican didn't start. Is the Pelican package installed?"
|
||||||
return 1
|
return 1
|
||||||
elif ! alive $$srv_pid ; then
|
elif ! alive $srv_pid ; then
|
||||||
echo "The HTTP server didn't start. Is there another service using port" $$port "?"
|
echo "The HTTP server didn't start. Is there another service using port" $port "?"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo 'Pelican and HTTP server processes now running in background.'
|
echo 'Pelican and HTTP server processes now running in background.'
|
||||||
|
|
@ -84,17 +85,17 @@ function start_up(){
|
||||||
###
|
###
|
||||||
# MAIN
|
# MAIN
|
||||||
###
|
###
|
||||||
[[ ($$# -eq 0) || ($$# -gt 2) ]] && usage
|
[[ ($# -eq 0) || ($# -gt 2) ]] && usage
|
||||||
port=''
|
port=''
|
||||||
[[ $$# -eq 2 ]] && port=$$2
|
[[ $# -eq 2 ]] && port=$2
|
||||||
|
|
||||||
if [[ $$1 == "stop" ]]; then
|
if [[ $1 == "stop" ]]; then
|
||||||
shut_down
|
shut_down
|
||||||
elif [[ $$1 == "restart" ]]; then
|
elif [[ $1 == "restart" ]]; then
|
||||||
shut_down
|
shut_down
|
||||||
start_up $$port
|
start_up $port
|
||||||
elif [[ $$1 == "start" ]]; then
|
elif [[ $1 == "start" ]]; then
|
||||||
if ! start_up $$port; then
|
if ! start_up $port; then
|
||||||
shut_down
|
shut_down
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
@ -14,17 +14,23 @@ from pelican.server import ComplexHTTPRequestHandler
|
||||||
env.deploy_path = 'output'
|
env.deploy_path = 'output'
|
||||||
DEPLOY_PATH = env.deploy_path
|
DEPLOY_PATH = env.deploy_path
|
||||||
|
|
||||||
|
{% if ssh %}
|
||||||
# Remote server configuration
|
# Remote server configuration
|
||||||
production = '$ssh_user@$ssh_host:$ssh_port'
|
production = '{{ssh_user}}@{{ssh_host}}:{{ssh_port}}'
|
||||||
dest_path = '$ssh_target_dir'
|
dest_path = '{{ssh_target_dir}}'
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if cloudfiles %}
|
||||||
# Rackspace Cloud Files configuration settings
|
# Rackspace Cloud Files configuration settings
|
||||||
env.cloudfiles_username = '$cloudfiles_username'
|
env.cloudfiles_username = '{{cloudfiles_username}}'
|
||||||
env.cloudfiles_api_key = '$cloudfiles_api_key'
|
env.cloudfiles_api_key = '{{cloudfiles_api_key}}'
|
||||||
env.cloudfiles_container = '$cloudfiles_container'
|
env.cloudfiles_container = '{{cloudfiles_container}}'
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if github %}
|
||||||
# Github Pages configuration
|
# Github Pages configuration
|
||||||
env.github_pages_branch = "$github_pages_branch"
|
env.github_pages_branch = '{{github_pages_branch}}'
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# Port for `serve`
|
# Port for `serve`
|
||||||
PORT = 8000
|
PORT = 8000
|
||||||
|
|
@ -68,6 +74,7 @@ def preview():
|
||||||
"""Build production version of site"""
|
"""Build production version of site"""
|
||||||
local('pelican -s publishconf.py')
|
local('pelican -s publishconf.py')
|
||||||
|
|
||||||
|
{% if cloudfiles %}
|
||||||
def cf_upload():
|
def cf_upload():
|
||||||
"""Publish to Rackspace Cloud Files"""
|
"""Publish to Rackspace Cloud Files"""
|
||||||
rebuild()
|
rebuild()
|
||||||
|
|
@ -76,6 +83,7 @@ def cf_upload():
|
||||||
'-U {cloudfiles_username} '
|
'-U {cloudfiles_username} '
|
||||||
'-K {cloudfiles_api_key} '
|
'-K {cloudfiles_api_key} '
|
||||||
'upload -c {cloudfiles_container} .'.format(**env))
|
'upload -c {cloudfiles_container} .'.format(**env))
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
@hosts(production)
|
@hosts(production)
|
||||||
def publish():
|
def publish():
|
||||||
|
|
@ -89,7 +97,9 @@ def publish():
|
||||||
extra_opts='-c',
|
extra_opts='-c',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
{% if github %}
|
||||||
def gh_pages():
|
def gh_pages():
|
||||||
"""Publish to GitHub Pages"""
|
"""Publish to GitHub Pages"""
|
||||||
rebuild()
|
rebuild()
|
||||||
local("ghp-import -b {github_pages_branch} {deploy_path} -p".format(**env))
|
local("ghp-import -b {github_pages_branch} {deploy_path} -p".format(**env))
|
||||||
|
{% endif %}
|
||||||
|
|
@ -2,15 +2,15 @@
|
||||||
# -*- coding: utf-8 -*- #
|
# -*- coding: utf-8 -*- #
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
AUTHOR = $author
|
AUTHOR = {{author}}
|
||||||
SITENAME = $sitename
|
SITENAME = {{sitename}}
|
||||||
SITEURL = ''
|
SITEURL = ''
|
||||||
|
|
||||||
PATH = 'content'
|
PATH = 'content'
|
||||||
|
|
||||||
TIMEZONE = $timezone
|
TIMEZONE = {{timezone}}
|
||||||
|
|
||||||
DEFAULT_LANG = $lang
|
DEFAULT_LANG = {{lang}}
|
||||||
|
|
||||||
# Feed generation is usually not desired when developing
|
# Feed generation is usually not desired when developing
|
||||||
FEED_ALL_ATOM = None
|
FEED_ALL_ATOM = None
|
||||||
|
|
@ -29,7 +29,7 @@ LINKS = (('Pelican', 'http://getpelican.com/'),
|
||||||
SOCIAL = (('You can add links in your config file', '#'),
|
SOCIAL = (('You can add links in your config file', '#'),
|
||||||
('Another social link', '#'),)
|
('Another social link', '#'),)
|
||||||
|
|
||||||
DEFAULT_PAGINATION = $default_pagination
|
DEFAULT_PAGINATION = {{default_pagination}}
|
||||||
|
|
||||||
# Uncomment following line if you want document-relative URLs when developing
|
# Uncomment following line if you want document-relative URLs when developing
|
||||||
#RELATIVE_URLS = True
|
#RELATIVE_URLS = True
|
||||||
|
|
@ -11,7 +11,7 @@ sys.path.append(os.curdir)
|
||||||
from pelicanconf import *
|
from pelicanconf import *
|
||||||
|
|
||||||
# If your site is available via HTTPS, make sure SITEURL begins with https://
|
# If your site is available via HTTPS, make sure SITEURL begins with https://
|
||||||
SITEURL = '$siteurl'
|
SITEURL = '{{siteurl}}'
|
||||||
RELATIVE_URLS = False
|
RELATIVE_URLS = False
|
||||||
|
|
||||||
FEED_ALL_ATOM = 'feeds/all.atom.xml'
|
FEED_ALL_ATOM = 'feeds/all.atom.xml'
|
||||||
Loading…
Add table
Add a link
Reference in a new issue