Skip to content

Commit

Permalink
fixup! refactor: Add backlinks metadata to autorefs elements
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Feb 7, 2025
1 parent 0fd25e6 commit 8a4de0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from collections.abc import Iterator, Mapping, MutableMapping, Sequence

from mkdocs.config.defaults import MkDocsConfig
from mkdocs_autorefs.plugin import Backlink


if sys.version_info >= (3, 11):
Expand Down Expand Up @@ -274,7 +275,7 @@ def render(self, data: CollectorItem, options: PythonOptions) -> str: # noqa: D
},
)

def render_backlinks(self, backlinks: Mapping[str, Iterable[str]]) -> str: # noqa: D102 (ignore missing docstring)
def render_backlinks(self, backlinks: Mapping[str, Iterable[Backlink]]) -> str: # noqa: D102 (ignore missing docstring)
template = self.env.get_template("backlinks.html.jinja")
verbose_type = {key: key.capitalize().replace("-by", " by") for key in backlinks.keys()}
return template.render(backlinks=backlinks, config=self.get_options({}), verbose_type=verbose_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ Context:
{% for backlink_type, backlink_list in backlinks | dictsort %}
<b class="doc doc-backlink-type">{{ verbose_type[backlink_type] }}:</b>
<ul class="doc doc-backlink-list">
{% for url, title in backlink_list | sort(attribute=1) %}
<li><a href="{{ url }}" class="doc doc-backlink">{{ (title or url.split("#", 1)[-1]) | safe }}</a></li>
{% for backlink in backlink_list | sort(attribute="crumbs") %}
<li class="doc doc-backlink">
{% for crumb in backlink.crumbs | reverse %}
{% if crumb.url %}
<a class="doc doc-backlink-crumb" href="{{ crumb.url }}">{{ crumb.title | safe }}</a>
{% else %}
<span class="doc doc-backlink-crumb">{{ crumb.title | safe }}</span>
{% endif %}
{% if not loop.last %}
<span class="twemoji">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6z"/></svg>
</span>
{% endif %}
{% endfor %}
</li>
{% endfor %}
</ul>
{% endfor %}
Expand Down

0 comments on commit 8a4de0c

Please sign in to comment.