Skip to content

Commit

Permalink
Remove anchor on benchmarks in breadcrumbs
Browse files Browse the repository at this point in the history
* Remove anchor on benchmarks in breadcrumbs when on the benchmarks page
* Add `page_type` to each template run for page type specific logic
  • Loading branch information
mkly committed Mar 1, 2024
1 parent 84f101f commit 1beb740
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/coffee/static_site_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def _generate_index_page(self, output_dir: pathlib.Path) -> None:
self._write_file(
output=output_dir / "index.html",
template_name="index.html",
page_type="index",
)

def _grouped_benchmark_scores(self, benchmark_scores: list[BenchmarkScore]) -> dict:
Expand All @@ -166,6 +167,7 @@ def _generate_benchmarks_page(self, benchmark_scores: list[BenchmarkScore], outp
template_name="benchmarks.html",
grouped_benchmark_scores=self._grouped_benchmark_scores(benchmark_scores),
show_benchmark_header=True,
page_type="benchmarks",
)

def _generate_benchmark_pages(self, benchmark_scores: list[BenchmarkScore], output_dir: pathlib.Path) -> None:
Expand All @@ -177,6 +179,7 @@ def _generate_benchmark_pages(self, benchmark_scores: list[BenchmarkScore], outp
benchmark_definition=benchmark_definition,
grouped_benchmark_scores=self._grouped_benchmark_scores(benchmark_scores),
stars_description=STARS_DESCRIPTION,
page_type="benchmark",
)

def _generate_test_report_pages(self, benchmark_scores: list[BenchmarkScore], output_dir: pathlib.Path) -> None:
Expand All @@ -187,4 +190,5 @@ def _generate_test_report_pages(self, benchmark_scores: list[BenchmarkScore], ou
template_name="test_report.html",
benchmark_score=benchmark_score,
stars_description=STARS_DESCRIPTION,
page_type="test_report",
)
2 changes: 1 addition & 1 deletion src/coffee/templates/benchmarks.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block title %}Benchmarks{% endblock %}

{% block content %}
{{ breadcrumb(benchmark_score, benchmark_definition) }}
{{ breadcrumb(benchmark_score, benchmark_definition, page_type="benchmarks") }}

<div class="mlc--section">
<h1 class="mlc--header">AI Safety Benchmarks {% include "_provisional.html" %}</h1>
Expand Down
8 changes: 6 additions & 2 deletions src/coffee/templates/macros/breadcrumb.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{% macro breadcrumb(benchmark_score, benchmark_definition) %}
{% macro breadcrumb(benchmark_score, benchmark_definition, page_type) %}
<nav aria-label="breadcrumb">
<ul>
<li><a href="{{ root_path() }}">ML Commons</a></li>
<li><a href="{{ benchmarks_path() }}">Benchmarks</a></li>
{% if page_type == "benchmarks" %}
<li>Benchmarks</li>
{% else %}
<li><a href="{{ benchmarks_path() }}">Benchmarks</a></li>
{% endif %}
{% if benchmark_score %}
<li>
<a href="{{ benchmark_path(benchmark_score.benchmark_definition.path_name()) }}">{{ benchmark_score.benchmark_definition.name() }}</a>
Expand Down
13 changes: 13 additions & 0 deletions tests/templates/macros/test_breadcrumb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import re


def test_display_breadcrumb(benchmark_score, template_env):
template = template_env.get_template("macros/breadcrumb.html")
result = template.module.breadcrumb(benchmark_score, benchmark_score.benchmark_definition)
Expand All @@ -8,3 +11,13 @@ def test_display_breadcrumb(benchmark_score, template_env):
assert "Benchmarks" in result
assert 'href="general_chat_bot_benchmark.html"' not in result
assert "General Chat Bot" in result


def test_breadcrum_no_link_benchmarks_page_type(benchmark_score, template_env):
template = template_env.get_template("macros/breadcrumb.html")
result = template.module.breadcrumb(benchmark_score, benchmark_score.benchmark_definition, "benchmarks")
assert "Benchmarks" in result
assert re.search("<li.*>Benchmarks</li>", result) is not None
result = template.module.breadcrumb(benchmark_score, benchmark_score.benchmark_definition)
assert re.search("<li.*>Benchmarks</li>", result) is None
assert re.search(r"<li.*><a.*>Benchmarks</a></li>", result) is not None

0 comments on commit 1beb740

Please sign in to comment.