forked from github/pelican
Competing static site generators integrate the functionality of regenerating content and serving it into their main executable. In pelican this functionality used to be in an external script `develop_server.sh` which resides in the blog base directory. This has the disadvantage that changes in pelican can break the `develop_server.sh` scripts which will not automatically be upgraded together with pelican by package managers. Thus, pelican should integrate this functionality into its main executable. To this end, this commit removes `develop_server.sh` and adds three command line options to the pelican executable: * `-l/--listen` starts the HTTP server (`-s/--serve` was already taken) * `-p/--port` specifies the port to listen at * `-b/--bind` specifies the IP to bind to `--listen` and `--autoreload` can be used together to achieve the same effect that other static site generators offer: Serve files via HTTP while at the same time auto-generating the content. Since the `develop_server.sh` script was removed, pelican-quickstart looses the `develop` option. Since the `develop_server.sh` script was removed, the Makefile looses the `stopserver` target and the `devserver` target is replaced by running `pelican -l` in the foreground. Since pelican now offers the `--listen` option, the fabfile uses that instead of starting the socketserver itself.
95 lines
2.4 KiB
Django/Jinja
95 lines
2.4 KiB
Django/Jinja
from fabric.api import *
|
|
import fabric.contrib.project as project
|
|
import os
|
|
import shutil
|
|
import sys
|
|
|
|
# Local path configuration (can be absolute or relative to fabfile)
|
|
env.deploy_path = 'output'
|
|
DEPLOY_PATH = env.deploy_path
|
|
|
|
{% if ssh %}
|
|
# Remote server configuration
|
|
production = '{{ssh_user}}@{{ssh_host}}:{{ssh_port}}'
|
|
dest_path = '{{ssh_target_dir}}'
|
|
|
|
{% endif %}
|
|
{% if cloudfiles %}
|
|
# Rackspace Cloud Files configuration settings
|
|
env.cloudfiles_username = '{{cloudfiles_username}}'
|
|
env.cloudfiles_api_key = '{{cloudfiles_api_key}}'
|
|
env.cloudfiles_container = '{{cloudfiles_container}}'
|
|
|
|
{% endif %}
|
|
{% if github %}
|
|
# Github Pages configuration
|
|
env.github_pages_branch = '{{github_pages_branch}}'
|
|
{% endif %}
|
|
|
|
# Port for `serve`
|
|
PORT = 8000
|
|
|
|
def clean():
|
|
"""Remove generated files"""
|
|
if os.path.isdir(DEPLOY_PATH):
|
|
shutil.rmtree(DEPLOY_PATH)
|
|
os.makedirs(DEPLOY_PATH)
|
|
|
|
def build():
|
|
"""Build local version of site"""
|
|
local('pelican -s pelicanconf.py')
|
|
|
|
def rebuild():
|
|
"""`build` with the delete switch"""
|
|
local('pelican -d -s pelicanconf.py')
|
|
|
|
def regenerate():
|
|
"""Automatically regenerate site upon file modification"""
|
|
local('pelican -r -s pelicanconf.py')
|
|
|
|
def serve():
|
|
"""Serve site at http://localhost:8000/"""
|
|
local('pelican -l -s pelicanconf.py')
|
|
|
|
def devserver():
|
|
"""Serve site at http://localhost:8000/ and regenerate automatically"""
|
|
local('pelican -r -l -s pelicanconf.py')
|
|
|
|
def reserve():
|
|
"""`build`, then `serve`"""
|
|
build()
|
|
serve()
|
|
|
|
def preview():
|
|
"""Build production version of site"""
|
|
local('pelican -s publishconf.py')
|
|
|
|
{% if cloudfiles %}
|
|
def cf_upload():
|
|
"""Publish to Rackspace Cloud Files"""
|
|
rebuild()
|
|
with lcd(DEPLOY_PATH):
|
|
local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
|
|
'-U {cloudfiles_username} '
|
|
'-K {cloudfiles_api_key} '
|
|
'upload -c {cloudfiles_container} .'.format(**env))
|
|
{% endif %}
|
|
|
|
@hosts(production)
|
|
def publish():
|
|
"""Publish to production via rsync"""
|
|
local('pelican -s publishconf.py')
|
|
project.rsync_project(
|
|
remote_dir=dest_path,
|
|
exclude=".DS_Store",
|
|
local_dir=DEPLOY_PATH.rstrip('/') + '/',
|
|
delete=True,
|
|
extra_opts='-c',
|
|
)
|
|
|
|
{% if github %}
|
|
def gh_pages():
|
|
"""Publish to GitHub Pages"""
|
|
rebuild()
|
|
local("ghp-import -b {github_pages_branch} {deploy_path} -p".format(**env))
|
|
{% endif %}
|