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
2 changes: 1 addition & 1 deletion LAST_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.9-dev1
1.0.9
11 changes: 11 additions & 0 deletions docs/nav/settings/show-footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Show footer

## Hiding the "Made with Dracula Theme for MkDocs" footer

```yml
theme:
name: dracula
show_footer: false
```

Defaults to `true`.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nav:
- Settings:
- nav/settings/favicon.md
- nav/settings/custom-highlight.md
- nav/settings/show-footer.md
- Development:
- nav/development/development-guide.md
- nav/development/release-notes.md
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_dracula_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.0.9-dev1"
__version__ = "1.0.9"

__author__ = "Fernando Celmer <email@fernandocelmer.com>"
__copyright__ = """MIT License
Expand Down
4 changes: 3 additions & 1 deletion mkdocs_dracula_theme/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@

<!-- block footer -->
{%- block footer %}
{% include "/modules/footer.html" %}
{% if config.theme.show_footer %}
{% include "/modules/footer.html" %}
{% endif %}
{%- endblock %}
<!-- endblock -->
</div>
Expand Down
2 changes: 2 additions & 0 deletions mkdocs_dracula_theme/mkdocs_theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ search_index_only: false

highlightjs: true
hljs_languages: []

show_footer: true
574 changes: 393 additions & 181 deletions poetry.lock

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
from pathlib import Path

import pytest
Expand All @@ -8,3 +9,35 @@
@pytest.fixture(scope="session")
def theme_dir():
return Path(mkdocs_dracula_theme.__file__).parent


@pytest.fixture()
def docs_dir(tmp_path):
d = tmp_path / "docs"
d.mkdir()
(d / "index.md").write_text("# Home\nHello world.\n")
return d


@pytest.fixture()
def build_site(tmp_path, docs_dir):
"""Factory: build a minimal MkDocs site and return the index.html content."""
from mkdocs.commands.build import build
from mkdocs.config import load_config

def _build(extra_theme_config: str = "") -> str:
config_text = textwrap.dedent(f"""
site_name: Test Site
docs_dir: {docs_dir}
site_dir: {tmp_path / "site"}
theme:
name: dracula
{extra_theme_config}
""")
cfg_path = tmp_path / "mkdocs.yml"
cfg_path.write_text(config_text)
cfg = load_config(str(cfg_path))
build(cfg)
return (tmp_path / "site" / "index.html").read_text()

return _build
73 changes: 73 additions & 0 deletions tests/test_custom_highlight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import unittest

import pytest


class TestCustomHighlight(unittest.TestCase):
@pytest.fixture(autouse=True)
def _inject_build_site(self, build_site):
self.build_site = build_site

def test_default_highlight_css_is_darcula(self):
html = self.build_site()

self.assertIn("assets/css/darcula-highlight.min.css", html)
self.assertNotIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/",
html,
)

def test_custom_highlight_css_overrides_default(self):
html = self.build_site("highlight_css: github.min.css")

self.assertIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css",
html,
)
self.assertNotIn("assets/css/darcula-highlight.min.css", html)

def test_highlightjs_enabled_by_default(self):
html = self.build_site()

self.assertIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js",
html,
)

def test_highlightjs_disabled_omits_script(self):
html = self.build_site("highlightjs: false")

self.assertNotIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js",
html,
)

def test_custom_highlight_js_overrides_default(self):
html = self.build_site("highlight_js: highlight.pack.min.js")

self.assertIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.pack.min.js",
html,
)

def test_hljs_languages_are_included(self):
html = self.build_site(
"hljs_languages:\n - python\n - go"
)

self.assertIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/languages/python.min.js",
html,
)
self.assertIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/languages/go.min.js",
html,
)

def test_no_hljs_languages_by_default(self):
html = self.build_site()

self.assertNotIn(
"cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/languages/",
html,
)
48 changes: 48 additions & 0 deletions tests/test_show_footer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Tests for PR #32 — show_footer config option."""

from pathlib import Path

import yaml

THEME_YML = (
Path(__file__).parent.parent / "mkdocs_dracula_theme" / "mkdocs_theme.yml"
)
FOOTER_TEXT = "Made with Dracula Theme for MkDocs"


class TestShowFooterDefault:
def test_default_config_declares_show_footer(self):
"""mkdocs_theme.yml must declare show_footer key."""
config = yaml.safe_load(THEME_YML.read_text())
assert "show_footer" in config, (
"show_footer key missing from mkdocs_theme.yml"
)

def test_default_value_is_true(self):
"""Default value of show_footer must be True (backwards-compatible)."""
config = yaml.safe_load(THEME_YML.read_text())
assert config["show_footer"] is True

def test_footer_rendered_by_default(self, build_site):
"""Footer is visible when show_footer is not set."""
html = build_site()
assert FOOTER_TEXT in html

def test_footer_rendered_when_explicitly_true(self, build_site):
"""Footer is visible when show_footer: true."""
html = build_site("show_footer: true")
assert FOOTER_TEXT in html

def test_footer_hidden_when_false(self, build_site):
"""Footer is absent when show_footer: false."""
html = build_site("show_footer: false")
assert FOOTER_TEXT not in html

def test_base_template_has_conditional(self):
"""base.html must wrap the footer include with show_footer conditional."""
base = (
Path(__file__).parent.parent / "mkdocs_dracula_theme" / "base.html"
).read_text()
assert "config.theme.show_footer" in base, (
"base.html must guard the footer include with {% if config.theme.show_footer %}"
)
Loading