def serve(hugo_args='', init_jupyter=True):
"""
Watch for changes in jupyter notebooks and render them anew while hugo runs.
Args:
init_jupyter: initialize jupyter if set to True
hugo_args: command-line arguments to be passed to `hugo server`
"""
observer = Observer()
observer.schedule(NotebookHandler(), 'notebooks')
observer.start()
hugo_process = sp.Popen(('hugo', 'serve', *shlex.split(hugo_args)))
if init_jupyter:
jupyter_process = sp.Popen(('jupyter', 'notebook'), cwd='notebooks')
local('open http://localhost:1313')
try:
print(crayons.green('Successfully initialized server(s)'),
crayons.yellow('press ctrl+C at any time to quit'),
)
while True:
pass
except KeyboardInterrupt:
print(crayons.yellow('Terminating'))
finally:
if init_jupyter:
print(crayons.yellow('shutting down jupyter'))
jupyter_process.kill()
print(crayons.yellow('shutting down watchdog'))
observer.stop()
observer.join()
print(crayons.yellow('shutting down hugo'))
hugo_process.kill()
print(crayons.green('all processes shut down successfully'))
sys.exit(0)
评论列表
文章目录