@@ -19,20 +19,25 @@ subparsers = parser.add_subparsers(metavar='<command>', title='commands')
19
19
20
20
DOCKER_RUN = [
21
21
'docker' , 'run' , '--init' , '-it' , '--rm' , '-v' ,
22
- f'{ os .getcwd ()} :/src:cached' , '-w=/src' , '-p' , '1313:1313' ,
22
+ f'{ os .getcwd ()} :/src:cached' , '-w=/src'
23
23
]
24
24
25
- DOCKER_HUGO = DOCKER_RUN + ['cibuilds/hugo:0.41' ]
26
-
27
- DOCKER_NODE = DOCKER_RUN + ['node:10.4.0-alpine' ]
28
-
29
25
def command (help ):
30
26
def decorator (func ):
31
27
parser = subparsers .add_parser (func .__name__ , help = help )
32
28
parser .set_defaults (func = func )
33
29
return func
34
30
return decorator
35
31
32
+ def run_in_hugo (command , bind_port = False ):
33
+ return run (
34
+ DOCKER_RUN + (['-p' , '1313:1313' ] if bind_port else []) +
35
+ ['cibuilds/hugo:0.41' ] + command
36
+ ).returncode
37
+
38
+ def run_in_node (command ):
39
+ return run (DOCKER_RUN + ['node:10.4.0-alpine' ] + command ).returncode
40
+
36
41
def open_in_browser ():
37
42
site = 'http://localhost:1313'
38
43
while True :
@@ -78,30 +83,30 @@ def algolia(args, remaining):
78
83
return run (['atomic-algolia' ]).returncode
79
84
if which ('npx' ):
80
85
return run (['npx' , 'atomic-algolia' ]).returncode
81
- return run ( DOCKER_NODE + ['npx' , 'atomic-algolia' ]). returncode
86
+ return run_in_node ( ['npx' , 'atomic-algolia' ])
82
87
83
88
@command ('Run a Hugo command' )
84
89
def hugo (args , remaining ):
85
- return run ( DOCKER_HUGO + ['hugo' ] + (remaining or [])). returncode
90
+ return run_in_hugo ( ['hugo' ] + (remaining or []))
86
91
87
92
@command ('Lint the resulting HTML' )
88
93
def lint (args , remaining ):
89
94
rc = hugo (None , None )
90
95
if rc :
91
96
return rc
92
- return run ( DOCKER_HUGO + [
97
+ return run_in_hugo ( [
93
98
'htmlproofer' , '--check-favicon' , '--check-html' , '--check-opengraph' ,
94
99
'--disable-external' , 'public'
95
- ]). returncode
100
+ ])
96
101
97
102
@command ('Open a shell' )
98
103
def sh (args , remaining ):
99
- return run ( DOCKER_HUGO + ['sh' ]). returncode
104
+ return run_in_hugo ( ['sh' ])
100
105
101
106
@command ('Start development' )
102
107
def start (args , remaining ):
103
108
Thread (target = open_in_browser ).start ()
104
- run ( DOCKER_HUGO + ['hugo' , 'server' , '--bind' , '0.0.0.0' , '--buildDrafts' ])
109
+ run_in_hugo ( ['hugo' , 'server' , '--bind' , '0.0.0.0' , '--buildDrafts' ], True )
105
110
106
111
if __name__ == '__main__' :
107
112
if len (sys .argv ) > 1 :
0 commit comments