This repository has been archived by the owner on Feb 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
61 lines (49 loc) · 1.45 KB
/
fabfile.py
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
import os
import datetime
import slugify
from fabric.api import puts, local
from jinja2 import Environment, FileSystemLoader
def new_post(title, slug=None):
"""
Creates a new blog post
"""
if slug is None:
slug = slugify.slugify(title)
header = len(slug) * '#'
now = datetime.datetime.now()
post_date = now.strftime("%Y-%m-%d %H:%M")
params = dict(
date=post_date,
title=title,
header=header,)
out_file = "rst/{}.rst".format(slug)
if not os.path.exists(out_file):
render("blog-post-template.rst", out_file, **params)
else:
print ("{} already exists.".format(out_file))
def make_html():
"""
Generates html as defined in MakeFile
"""
local("/usr/bin/make html", shell='/bin/bash')
def preview():
"""
Generates HTML and spaws firefox to preview in browser
"""
make_html()
local('firefox public/index.html&')
def publish():
"""
Leverages s3cmd to sync public/ to s3 bucket
"""
local('/usr/bin/s3cmd sync public/ s3://www.barrymorrison.com/')
def render(template, destination, **kwargs):
"""
Function to render new blog post
"""
jenv = Environment(loader=FileSystemLoader(['.', ]))
params = dict(**kwargs)
text = jenv.get_template(template).render(params)
with open(destination, "w") as output:
puts("Rendering: {} to {}".format(template, destination))
output.write(text.encode("utf-8"))