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

added support for pages to act as a link

closes #26
parent 61b0f5f8
No related branches found
No related tags found
No related merge requests found
Pipeline #313245 passed
......@@ -20,7 +20,7 @@
{%- else -%}
{%- if reftype == "tag" -%}
{{ tagcattitle|e }}
{%- else -%}
{%- elif reftype == "slug" -%}
{{ refpage.title|e }}
{%- endif -%}
{%- endif -%}
......@@ -35,42 +35,56 @@
{#- returns: (url, anchor, reflang, is_external, reftype, refid, refpage, tagcattitle, tagcatcolor)-#}
{%- macro parse_url(rawurl, lang) -%}
{%- set urlsplit = rawurl.split('#') -%}
{%- set anchor = urlsplit[1]|d(None) -%}
{%- set urlwoa = urlsplit[0] -%} {#- url without anchor -#}
{%- set ns = namespace(anchor=urlsplit[1]|d(None), url=None, page=None, tagcattitle=None, tagcatcolor=None, tagpage=None, reftype=None, refid=None, reflang=None, is_external = False) -%}
{%- set urlwoa = urlsplit[0] -%} {#- url without ns.anchor -#}
{%- if not urlwoa|length -%}
{{- caller("", anchor, lang, False, None, None, None, None, None) -}}
{{- caller("", ns.anchor, lang, False, None, None, None, None, None) -}}
{%- else -%}
{%- set components = urlwoa.split(':') -%}
{%- if components|length == 1 -%}
{%- set url = ['https://', urlwoa]|join('') -%}
{{- caller(url, anchor, lang, True, None, None, None, None, None) -}}
{%- set ns.url = ['https://', urlwoa]|join('') -%}
{{- caller(ns.url, ns.anchor, lang, True, None, None, None, None, None) -}}
{%- else -%}
{%- set reftype = components[0] -%}
{%- set refid = components[1] -%}
{%- set reflang = components[2]|d(lang) -%}
{%- set ns = namespace(url=None, page=None, tagtitle=None, tagcolor=None, tagpage=None, catcolor=None, cattitle=None) -%}
{%- if reftype == "slug" -%}
{%- call(page) get.page_by_slug(refid, reflang) -%}
{%- set ns.reftype = components[0] -%}
{%- set ns.refid = components[1] -%}
{%- set ns.reflang = components[2]|d(lang) -%}
{%- if ns.reftype == "slug" -%}
{%- call(page) get.page_by_slug(ns.refid, ns.reflang) -%}
{%- set ns.url = [siteurl, page.url]|join('/') -%}
{%- set ns.page = page -%}
{%- call(cattitle, catcolor, caturl, catpage, catpages) get.tag_by_name(page.category, reflang) -%}
{%- set ns.cattitle = cattitle -%}
{%- set ns.catcolor = catcolor -%}
{%- call(tagcattitle, tagcatcolor, caturl, catpage, catpages) get.tag_by_name(page.category, ns.reflang) -%}
{%- set ns.tagcattitle = tagcattitle -%}
{%- set ns.tagcatcolor = tagcatcolor -%}
{%- endcall -%}
{%- endcall -%}
{{- caller(ns.url, anchor, reflang, False, reftype, refid, ns.page, ns.cattitle, ns.catcolor) -}}
{%- elif reftype == "tag" -%}
{%- call(tagtitle, tagcolor, tagurl, tagpage, tagpages) get.tag_by_name(refid, reflang) -%}
{%- if 'link' in ns.page.metadata -%}
{%- call(parsedurl, anchor, reflang, is_external, reftype, refid, refpage, tagcattitle, tagcatcolor) parse_url(ns.page.metadata['link'], ns.reflang) -%}
{%- set ns.url = parsedurl -%}
{%- set ns.anchor = anchor -%}
{%- set ns.reflang = reflang -%}
{%- set ns.is_external = is_external -%}
{%- set ns.reftype = reftype -%}
{%- if not is_external -%}
{%- set ns.refid = refid -%}
{%- set ns.refpage = refpage -%}
{%- set ns.tagcattitle = tagcattitle -%}
{%- set ns.tagcatcolor = tagcatcolor -%}
{%- endif -%}
{%- endcall -%}
{%- endif -%}
{{- caller(ns.url, ns.anchor, ns.reflang, ns.is_external, ns.reftype, ns.refid, ns.page, ns.tagcattitle, ns.tagcatcolor) -}}
{%- elif ns.reftype == "tag" -%}
{%- call(tagcattitle, tagcatcolor, tagurl, tagpage, tagpages) get.tag_by_name(ns.refid, ns.reflang) -%}
{%- set ns.url = [siteurl, tagurl]|join('/') -%}
{%- set ns.tagtitle = tagtitle -%}
{%- set ns.tagcolor = tagcolor -%}
{%- set ns.tagcattitle = tagcattitle -%}
{%- set ns.tagcatcolor = tagcatcolor -%}
{%- set ns.tagpage = tagpage -%}
{%- endcall -%}
{{- caller(ns.url, anchor, reflang, False, reftype, refid, ns.tagpage, ns.tagtitle, ns.tagcolor) -}}
{{- caller(ns.url, ns.anchor, ns.reflang, False, ns.reftype, ns.refid, ns.tagpage, ns.tagcattitle, ns.tagcatcolor) -}}
{%- else -%}
{{- caller(urlwoa, anchor, reflang, True, None, None, None, None, None) -}}
{{- caller(urlwoa, ns.anchor, ns.reflang, True, None, None, None, None, None) -}}
{%- endif -%}
{%- endif -%}
{%- endif -%}
......
......@@ -14,7 +14,7 @@
{%- if item is string -%}
{%- set url = item -%}
{%- call(parsedurl, anchor, reflang, is_external, reftype, refid, refpage, tagcattitle, tagcatcolor) link.parse_url(url, lang) -%}
<li style="--category-color: {{ tagcatcolor }}">
<li {% if tagcatcolor -%}style="--category-color: {{ tagcatcolor }}"{%- endif -%}>
{{ link.render(url, None, lang) }}
</li>
{%- endcall -%}
......
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