Repository navigation
Expand file tree
/
Copy pathtasks.py
More file actions
70 lines (50 loc) · 1.46 KB
/
Copy pathtasks.py
File metadata and controls
70 lines (50 loc) · 1.46 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
# -*- coding: utf-8 -*-
import os
import shutil
import sys
import datetime
from pathlib import Path
from invoke import task
from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
import localconf as LOCAL_CONFIG
# Github Pages configuration
#'github_pages_branch': 'gh-pages',
COMMIT_MESSAGE = f"'Publish site on {datetime.date.today().isoformat()}'"
@task
def clean(_):
"""Remove generated files"""
path = Path(LOCAL_CONFIG.OUTPUT_PATH)
if path.exists():
assert path.is_dir()
shutil.rmtree(path)
path.mkdir(parents=True, exist_ok=False)
@task
def build(c):
"""Build local version of site"""
c.run('pelican -s localconf.py')
@task
def rebuild(c):
"""`build` with the delete switch"""
c.run('pelican -d -s localconf.py')
@task
def regenerate(c):
"""Automatically regenerate site upon file modification"""
c.run('pelican -r -s localconf.py')
@task
def serve(_):
"""Serve site at http://localhost:8000/"""
class AddressReuseTCPServer(RootedHTTPServer):
allow_reuse_address = True
server = AddressReuseTCPServer(
LOCAL_CONFIG.OUTPUT_PATH,
('', LOCAL_CONFIG.PORT),
ComplexHTTPRequestHandler)
print(f"Serving on port {LOCAL_CONFIG.PORT} ...", file=sys.stderr)
server.serve_forever()
@task(pre=[build, serve])
def reserve(_):
"""`build`, then `serve`"""
@task
def preview(c):
"""Build production version of site"""
c.run('pelican -s publishconf.py')