Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/mkdocs/extensions/relative_urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import markdown
import mkdocs
import os
import posixpath
import httpx
import hip


class URLProcessor(markdown.treeprocessors.Treeprocessor):
Expand All @@ -26,7 +25,7 @@ def run(self, root):

if link:
el.set(key, link)
url = httpx.URL(link)
url = hip.URL(link)
# We want to rewrite relative links... '/page'
# We don't want to rewrite external links. 'https://elsewhere.com/here'
# We don't want to rewrite anchor links. '#section'
Expand Down
34 changes: 27 additions & 7 deletions src/mkdocs/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,15 @@ def build(self, input, output):
input_dir = pathlib.Path(input)
output_dir = pathlib.Path(output)

print(DARK_GRAY + "Collected %d resources" % len(self.site) + RESET)
click.echo(
click.style("Collected %d resources" % len(self.site), fg='bright_black')
)
for page in self.site.pages:
print(GREEN + " + " + RESET + BOLD + str(page.path) + RESET + DARK_GRAY + " [markdown]" + RESET)
click.echo(
click.style(" + ", fg='green') +
click.style(str(page.path), bold=True) +
click.style(" [markdown]", fg='bright_black')
)
input_path = input_dir.joinpath(page.path)
output_path = output_dir.joinpath(page.build_path)

Expand All @@ -268,7 +274,11 @@ def build(self, input, output):
output_path.write_text(output)

for static in self.site.statics:
print(GREEN + " + " + RESET + BOLD + str(static.path) + RESET + DARK_GRAY + " [static]" + RESET)
click.echo(
click.style(" + ", fg='green') +
click.style(str(static.path), bold=True) +
click.style(" [static]", fg='bright_black')
)
input_path = input_dir.joinpath(static.path)
output_path = output_dir.joinpath(static.path)

Expand All @@ -278,12 +288,22 @@ def build(self, input, output):
def serve(self, input):
input_dir = pathlib.Path(input)

print(DARK_GRAY + "Serving %d resources" % len(self.site) + RESET)
click.echo(
click.style("Serving %d resources" % len(self.site), fg='bright_black')
)
for page in self.site.pages:
print(GREEN + " + " + RESET + BOLD + str(page.url) + RESET + DARK_GRAY + " [markdown]" + RESET)
click.echo(
click.style(" + ", fg='green') +
click.style(str(page.url), bold=True) +
click.style(" [markdown]", fg='bright_black')
)
for static in self.site.statics:
print(GREEN + " + " + RESET + BOLD + str(static.url) + RESET + DARK_GRAY + " [static]" + RESET)
print()
click.echo(
click.style(" + ", fg='green') +
click.style(str(static.url), bold=True) +
click.style(" [static]", fg='bright_black')
)
click.echo()

def app(request):
resource = self.site.lookup_by_url(request.url.path)
Expand Down
31 changes: 30 additions & 1 deletion tests/test_mkdocs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from click.testing import CliRunner
import os
import mkdocs
import pathlib


def test_mkdocs():
def test_mkdocs_help():
runner = CliRunner()
result = runner.invoke(mkdocs.mkdocs, ['--help'])
assert result.exit_code == 0
Expand All @@ -16,3 +18,30 @@ def test_mkdocs():
' build\n'
' serve\n'
)


def test_mkdocs_build(tmp_path: pathlib.Path):
# Setup
os.chdir(tmp_path)

docs = tmp_path / "docs"
docs.mkdir()

readme = docs / "README.md"
readme.write_text("# README\n\nhello world!\n")

site = tmp_path / "site"

homepage = site / "index.html"

# Test
runner = CliRunner()
result = runner.invoke(mkdocs.mkdocs, ['build'])
assert result.exit_code == 0
assert result.output == (
'Collected 1 resources\n'
' + README.md [markdown]\n'
)
assert site.exists()
assert homepage.exists()
assert "<p>hello world!</p>" in homepage.read_text()
Loading