/
lightning
executable file
·71 lines (55 loc) · 2.15 KB
/
lightning
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
#!/usr/bin/env python3
import argparse
import os
import sys
import time
realpath = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(realpath, 'src'))
from Site import BuildConfig, SiteConfig
from ArticleLoader import ArticleLoader
from SiteLoader import SiteLoader
from SiteBuilder import SiteBuilder
DEFAULT_COMMAND = 'build'
parser = argparse.ArgumentParser(description='Build a Lightning static site.')
parser.add_argument('command', type=str, nargs='?', help='The command to run.')
parser.add_argument('--output-root', '-o', dest='output_root',
help='Alternative output path.')
parser.add_argument('--build-config-path', '-b', dest='build_config_path',
help='The websites YAML path.', default='lightning.yaml')
parser.add_argument('--changed-file', '-f', dest='changed_files',
action='append', help='Specifically which files have need to be rebuilt.')
args = parser.parse_args()
def BuildSite(output_root=None):
start = time.time()
site_loader = SiteLoader(args.build_config_path)
site_loader.Load()
end = time.time()
print('Loaded site in %.2f seconds.' % (end - start))
if output_root:
site_loader.build_config.output_root = output_root
start = time.time()
builder = SiteBuilder(site_loader.build_config)
# Clean the old site before building the new one.
builder.Clean()
builder.BuildSite(site_loader.site_config)
end = time.time()
print('Built site in %.2f seconds.' % (end - start))
def BuildIncrementalSite(output_root=None, changed_files=[]):
start = time.time()
site_loader = SiteLoader()
changed_articles = site_loader.LoadForIncremental(changed_files)
builder = SiteBuilder(site_loader.build_config)
builder.BuildPartialSite(site_loader.site_config, changed_articles)
end = time.time()
print('Built site incrementally in %.2f seconds.' % (end - start))
if __name__ == '__main__':
# Parse arguments.
command = DEFAULT_COMMAND
if args and args.command:
command = args.command
is_incremental = bool(args.changed_files)
if command == 'build':
if is_incremental:
BuildIncrementalSite(args.output_root, args.changed_files)
else:
BuildSite(args.output_root)