-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtasks.py
More file actions
82 lines (56 loc) · 1.69 KB
/
tasks.py
File metadata and controls
82 lines (56 loc) · 1.69 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from invoke import task, Collection
import pelicanconf as conf
# Built-in modules
import os
import shutil
# External modules
import sass
namespace = Collection()
@task
def clean(ctx):
"""Remove the build directory."""
if os.path.isdir(conf.OUTPUT_PATH):
shutil.rmtree(conf.OUTPUT_PATH)
namespace.add_task(clean)
# Build
# =====
@task(clean)
def build_content(ctx):
"""Build the site."""
ctx.run("pelican")
@task
def build_theme(ctx):
"""Build the site theme (if you changed a .scss file)."""
src_path = os.path.join(conf.THEME, conf.BOOTSTRAP_THEME, "build.scss")
css = sass.compile(filename = src_path, output_style = "compressed",
precision = 8)
dest_path = os.path.join(conf.THEME, "static", "css",
"bootstrap.{}.min.css".format(conf.BOOTSTRAP_THEME))
with open(dest_path, "w") as dest:
dest.write(css)
ctx.run(
"node_modules/postcss-cli/bin/postcss "
"--use autoprefixer --replace " + dest_path
)
build = Collection("build")
build.add_task(build_content, "content", default = True)
build.add_task(build_theme, "theme")
namespace.add_collection(build)
# Other Tasks
# ===========
@task(build_content)
def serve(ctx, port = 8000):
"""Serve the site at http://localhost:8000/"""
os.chdir(conf.OUTPUT_PATH)
ctx.run("python -m pelican.server {}".format(port))
namespace.add_task(serve)
@task(clean)
def watch(ctx):
"""Automatically build the site when changes are saved."""
ctx.run("pelican --autoreload")
namespace.add_task(watch)
@task
def publish(ctx):
"""Build the site using production settings in publishconf.py."""
ctx.run("pelican -s ./publishconf.py")
namespace.add_task(publish)