From 772af3d42db8c64b9c8a58fd4c18789836b822c9 Mon Sep 17 00:00:00 2001 From: Jake <j.vondoemming@stud.uni-goettingen.de> Date: Fri, 3 May 2024 18:48:52 +0200 Subject: [PATCH] Added support for rel attributes in links closes GAUMI-fginfo/fg-website#62 --- fgs/datatypes.py | 14 ++++++++++++++ theme/templates/macros/common.html | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/fgs/datatypes.py b/fgs/datatypes.py index dbfd960..3655ee8 100644 --- a/fgs/datatypes.py +++ b/fgs/datatypes.py @@ -546,6 +546,20 @@ class Link: return self.url 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) + + diff --git a/theme/templates/macros/common.html b/theme/templates/macros/common.html index f06dfee..44384e0 100644 --- a/theme/templates/macros/common.html +++ b/theme/templates/macros/common.html @@ -149,7 +149,7 @@ {%- endmacro -%} {%- 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) -%} {%- set ns.url = resolvedlink.urlwithanchor -%} {%- set ns.objtype = objtype -%} @@ -163,8 +163,11 @@ {%- endif -%} {%- endif -%} {%- endcall -%} + {%- if ns.objtype == "slug" -%} + {%- set ns.rel = ns.obj.link.rel -%} + {%- endif -%} {%- 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) -}} </a> {%- endmacro -%} -- GitLab