|
@@ -0,0 +1,112 @@
|
|
1
|
+# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+import os
|
|
4
|
+import shutil
|
|
5
|
+import sys
|
|
6
|
+import datetime
|
|
7
|
+
|
|
8
|
+from invoke import task
|
|
9
|
+from invoke.util import cd
|
|
10
|
+from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
|
|
11
|
+from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
|
|
12
|
+
|
|
13
|
+SETTINGS_FILE_BASE = 'pelicanconf.py'
|
|
14
|
+SETTINGS = {}
|
|
15
|
+SETTINGS.update(DEFAULT_CONFIG)
|
|
16
|
+LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
|
|
17
|
+SETTINGS.update(LOCAL_SETTINGS)
|
|
18
|
+
|
|
19
|
+CONFIG = {
|
|
20
|
+ 'settings_base': SETTINGS_FILE_BASE,
|
|
21
|
+ 'settings_publish': 'publishconf.py',
|
|
22
|
+ # Output path. Can be absolute or relative to tasks.py. Default: 'output'
|
|
23
|
+ 'deploy_path': SETTINGS['OUTPUT_PATH'],
|
|
24
|
+ # Remote server configuration
|
|
25
|
+ 'production': 'www-git@www2.frepoteries.fr:22',
|
|
26
|
+ 'dest_path': '/home/wwww-git/scop-cli',
|
|
27
|
+ # Port for `serve`
|
|
28
|
+ 'port': 8000,
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+@task
|
|
32
|
+def clean(c):
|
|
33
|
+ """Remove generated files"""
|
|
34
|
+ if os.path.isdir(CONFIG['deploy_path']):
|
|
35
|
+ shutil.rmtree(CONFIG['deploy_path'])
|
|
36
|
+ os.makedirs(CONFIG['deploy_path'])
|
|
37
|
+
|
|
38
|
+@task
|
|
39
|
+def build(c):
|
|
40
|
+ """Build local version of site"""
|
|
41
|
+ c.run('pelican -s {settings_base}'.format(**CONFIG))
|
|
42
|
+
|
|
43
|
+@task
|
|
44
|
+def rebuild(c):
|
|
45
|
+ """`build` with the delete switch"""
|
|
46
|
+ c.run('pelican -d -s {settings_base}'.format(**CONFIG))
|
|
47
|
+
|
|
48
|
+@task
|
|
49
|
+def regenerate(c):
|
|
50
|
+ """Automatically regenerate site upon file modification"""
|
|
51
|
+ c.run('pelican -r -s {settings_base}'.format(**CONFIG))
|
|
52
|
+
|
|
53
|
+@task
|
|
54
|
+def serve(c):
|
|
55
|
+ """Serve site at http://localhost:$PORT/ (default port is 8000)"""
|
|
56
|
+
|
|
57
|
+ class AddressReuseTCPServer(RootedHTTPServer):
|
|
58
|
+ allow_reuse_address = True
|
|
59
|
+
|
|
60
|
+ server = AddressReuseTCPServer(
|
|
61
|
+ CONFIG['deploy_path'],
|
|
62
|
+ ('', CONFIG['port']),
|
|
63
|
+ ComplexHTTPRequestHandler)
|
|
64
|
+
|
|
65
|
+ sys.stderr.write('Serving on port {port} ...\n'.format(**CONFIG))
|
|
66
|
+ server.serve_forever()
|
|
67
|
+
|
|
68
|
+@task
|
|
69
|
+def reserve(c):
|
|
70
|
+ """`build`, then `serve`"""
|
|
71
|
+ build(c)
|
|
72
|
+ serve(c)
|
|
73
|
+
|
|
74
|
+@task
|
|
75
|
+def preview(c):
|
|
76
|
+ """Build production version of site"""
|
|
77
|
+ c.run('pelican -s {settings_publish}'.format(**CONFIG))
|
|
78
|
+
|
|
79
|
+@task
|
|
80
|
+def livereload(c):
|
|
81
|
+ """Automatically reload browser tab upon file modification."""
|
|
82
|
+ from livereload import Server
|
|
83
|
+ build(c)
|
|
84
|
+ server = Server()
|
|
85
|
+ # Watch the base settings file
|
|
86
|
+ server.watch(CONFIG['settings_base'], lambda: build(c))
|
|
87
|
+ # Watch content source files
|
|
88
|
+ content_file_extensions = ['.md', '.rst']
|
|
89
|
+ for extension in content_file_extensions:
|
|
90
|
+ content_blob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
|
|
91
|
+ server.watch(content_blob, lambda: build(c))
|
|
92
|
+ # Watch the theme's templates and static assets
|
|
93
|
+ theme_path = SETTINGS['THEME']
|
|
94
|
+ server.watch('{}/templates/*.html'.format(theme_path), lambda: build(c))
|
|
95
|
+ static_file_extensions = ['.css', '.js']
|
|
96
|
+ for extension in static_file_extensions:
|
|
97
|
+ static_file = '{0}/static/**/*{1}'.format(theme_path, extension)
|
|
98
|
+ server.watch(static_file, lambda: build(c))
|
|
99
|
+ # Serve output path on configured port
|
|
100
|
+ server.serve(port=CONFIG['port'], root=CONFIG['deploy_path'])
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+@task
|
|
104
|
+def publish(c):
|
|
105
|
+ """Publish to production via rsync"""
|
|
106
|
+ c.run('pelican -s {settings_publish}'.format(**CONFIG))
|
|
107
|
+ c.run(
|
|
108
|
+ 'rsync --delete --exclude ".DS_Store" -pthrvz -c '
|
|
109
|
+ '{} {production}:{dest_path}'.format(
|
|
110
|
+ CONFIG['deploy_path'].rstrip('/') + '/',
|
|
111
|
+ **CONFIG))
|
|
112
|
+
|