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