Skip to content
Snippets Groups Projects
Verified Commit 772af3d4 authored by Jake's avatar Jake
Browse files

Added support for rel attributes in links

closes #62
parent 846179c5
No related branches found
No related tags found
No related merge requests found
Pipeline #463864 failed
...@@ -546,6 +546,20 @@ class Link: ...@@ -546,6 +546,20 @@ class Link:
return self.url return self.url
urlwithanchor = property(get_urlwithanchor, None, None) urlwithanchor = property(get_urlwithanchor, None, None)
def get_rel(self) -> str|None:
"""
Get the relation in the context of the rel html attribute for this link
or None if no relation is known.
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel
"""
if self.type != "slug":
return None
if "rel" not in self.page.metadata:
return None
return self.page.metadata["rel"]
rel = property(get_rel, None, None)
......
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
{%- endmacro -%} {%- endmacro -%}
{%- macro render_link_raw(link, content, lang, attr, title) -%} {%- macro render_link_raw(link, content, lang, attr, title) -%}
{%- set ns = namespace(relation=None, url=None, objtype=None, obj=None) -%} {%- set ns = namespace(relation=None, url=None, objtype=None, obj=None, rel=None) -%}
{%- call(resolvedlink, objtype, obj) resolve_link(link) -%} {%- call(resolvedlink, objtype, obj) resolve_link(link) -%}
{%- set ns.url = resolvedlink.urlwithanchor -%} {%- set ns.url = resolvedlink.urlwithanchor -%}
{%- set ns.objtype = objtype -%} {%- set ns.objtype = objtype -%}
...@@ -163,8 +163,11 @@ ...@@ -163,8 +163,11 @@
{%- endif -%} {%- endif -%}
{%- endif -%} {%- endif -%}
{%- endcall -%} {%- endcall -%}
{%- if ns.objtype == "slug" -%}
{%- set ns.rel = ns.obj.link.rel -%}
{%- endif -%}
{%- set target = config.link_target[ns.relation] -%} {%- set target = config.link_target[ns.relation] -%}
<a {{ render_attr(attr, lang, extra_classes=[ns.relation], extra={"href": ns.url, "title": {"value":title, "escape": true}, "target": target}) }}> <a {{ render_attr(attr, lang, extra_classes=[ns.relation], extra={"href": ns.url, "title": {"value":title, "escape": true}, "target": target, "rel": ns.rel}) }}>
{{- caller(ns.objtype, ns.obj,ns.url,ns.relation) -}} {{- caller(ns.objtype, ns.obj,ns.url,ns.relation) -}}
</a> </a>
{%- endmacro -%} {%- endmacro -%}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment