Exemplo n.º 1
0
def show(
    markdown_file: Path,
    host: str = 'localhost',
    port: int = 8123,
    no_warmup: bool = False,
):
    """
    Visualize your presentation (default).
    """
    markdown_file = Path(markdown_file)
    config = load_config()

    # Initial generation
    generate(markdown_file, no_warmup=no_warmup)

    observer = Observer()
    url = 'http://{host}:{port}'.format(host=host, port=port)
    reload_url = url + '/forcereload'
    ignore_regexes = [r'.*/\.[^/]*']
    handler = Handler(regexes=['.*'],
                      ignore_regexes=ignore_regexes,
                      ignore_directories=True)
    handler.configure(markdown_file, reload_url)
    observer.schedule(handler, '.', recursive=True)
    observer.start()

    server = Server()
    server.root = str(config['output_path'])
    server.application(port, host, liveport=None, debug=True, live_css=True)
    threading.Thread(target=webbrowser.open, args=(url, )).start()
    add_reload_hook(lambda: IOLoop.instance().close(all_fds=True))
    IOLoop.instance().start()
Exemplo n.º 2
0
        ignored_files = []
        for path in configuration.get('ignore'):
            ignored_files.append(os.path.realpath(path))

        builder = sphinx_autobuild.SphinxBuilder(
            outdir=build_folder,
            args=['-b', 'html', source_folder, build_folder] + sys.argv[1:],
            ignored=ignored_files)

        server = Server(watcher=sphinx_autobuild.LivereloadWatchdogWatcher())
        server.watch(source_folder, builder)
        server.watch(build_folder)

        builder.build()

        server.application = server_application.__get__(server, Server)
        server.serve(port=8000, host='0.0.0.0', root=build_folder)
    else:
        # Building once when server starts
        builder = sphinx_autobuild.SphinxBuilder(
            outdir=build_folder,
            args=['-b', 'html', source_folder, build_folder] + sys.argv[1:])
        builder.build()

        sys.argv = ['nouser', '8000']

        if configuration.get('credentials')['username'] is not None:
            auth = configuration.get(
                'credentials')['username'] + ':' + configuration.get(
                    'credentials')['password']
            key = base64.b64encode(auth)