예제 #1
0
def test_build(tmpdir):
    input_dir = os.path.join(tmpdir, "input")
    output_dir = os.path.join(tmpdir, "output")
    template_dir = os.path.join(tmpdir, "templates")
    index_md = os.path.join(input_dir, "index.md")
    favicon = os.path.join(input_dir, "favicon.ico")
    a_md = os.path.join(input_dir, "topics", "a.md")
    b_md = os.path.join(input_dir, "topics", "b.md")
    base_html = os.path.join(template_dir, "base.html")
    write_file(index_md,
               "# index\n[link to a](topics/a.md) [link to b](topics/b.md)")
    write_file(a_md, "# a\n[link to b](b.md) [link to index](../index.md)")
    write_file(b_md, "# b\n[link to a](a.md) [link to index](../index.md)")
    write_file(favicon, "xxx")
    write_file(base_html, "<html><body>{{ content }}</body></html>")

    config = {
        "site": {
            "url": "/"
        },
        "build": {
            "input_dir": input_dir,
            "output_dir": output_dir,
            "template_dir": template_dir,
        },
        "nav": {
            "Homepage": "index.md",
            "Topics": {
                "Topic A": "topics/a.md",
                "Topic B": "topics/b.md"
            },
        },
    }
    mkdocs2.build(config=config)
예제 #2
0
def serve(config_file: typing.TextIO) -> None:  # pragma: nocover
    content = config_file.read()
    config = yaml.load(content)

    with tempfile.TemporaryDirectory() as tmpdir:
        config["site"]["url"] = "/"
        config["build"]["output_dir"] = tmpdir
        mkdocs2.build(config)
        os.chdir(tmpdir)
        addr = ("", 8000)
        handler = http.server.SimpleHTTPRequestHandler
        socketserver.TCPServer.allow_reuse_address = True
        with socketserver.TCPServer(addr, handler) as httpd:
            msg = 'Documentation available at "http://127.0.0.1:8000/" (Ctrl+C to quit)'
            click.echo(msg)
            httpd.serve_forever()
예제 #3
0
def test_build(tmpdir):
    input_dir = os.path.join(tmpdir, "input")
    output_dir = os.path.join(tmpdir, "output")
    template_dir = os.path.join(tmpdir, "templates")
    index_md = os.path.join(input_dir, "index.md")
    favicon = os.path.join(input_dir, "img", "favicon.ico")
    a_md = os.path.join(input_dir, "topics", "a.md")
    b_md = os.path.join(input_dir, "topics", "b.md")
    base_html = os.path.join(template_dir, "base.html")
    write_file(index_md, "# index\n[link to a](topics/a.md) [link to b](topics/b.md)")
    write_file(a_md, "# a\n[link to b](b.md) [link to index](../index.md)")
    write_file(b_md, "# b\n[link to a](a.md) [link to index](../index.md)")
    write_file(favicon, "xxx")
    write_file(base_html, "<html><body>{{ content }}</body></html>")

    config = {
        "build": {
            "input_dir": input_dir,
            "output_dir": output_dir,
            "template_dir": template_dir,
        },
        "nav": {
            "Homepage": "index.md",
            "Topics": {"Topic A": "topics/a.md", "Topic B": "topics/b.md"},
        },
        "convertors": [
            "mkdocs2.convertors.MarkdownPages",
            "mkdocs2.convertors.CodeHighlight",
            "mkdocs2.convertors.StaticFiles",
        ],
    }
    mkdocs2.build(config=config)

    expected_files = [
        os.path.join(output_dir, "index.html"),
        os.path.join(output_dir, "topics", "a", "index.html"),
        os.path.join(output_dir, "topics", "b", "index.html"),
        os.path.join(output_dir, "img", "favicon.ico"),
        os.path.join(output_dir, "css", "highlight.css"),
    ]
    for path in expected_files:
        assert os.path.exists(path)
예제 #4
0
def build(config_file: typing.TextIO) -> None:
    content = config_file.read()
    config = yaml.load(content)
    mkdocs2.build(config)