diff --git a/theme/templates/macros/getters.html b/theme/templates/macros/getters.html new file mode 100644 index 0000000000000000000000000000000000000000..6e9313af0b08dbdafde8e69df52f3ae5098669dd --- /dev/null +++ b/theme/templates/macros/getters.html @@ -0,0 +1,53 @@ +{%- macro category_by_name(catname, ignore_native = False) -%} + {%- if ignore_native -%} + {{- caller(null, sc.categories[catname], null) -}} + {%- else -%} + {%- for nativecat, catarticles in categories -%} + {%- if nativecat.name == catname -%} + {{- caller(nativecat, sc.categories[catname], catarticles) -}} + {%- endif -%} + {%- endfor -%} + {%- endif -%} +{%- endmacro -%} + +{%- macro tag_by_name(tagname) -%} + {%- for nativetag, tagarticles in tags -%} + {%- if nativetag.name == tagname -%} + {%- if tagname in sc.categories -%} + {{- caller(nativetag, sc.categories[tagname], tagarticles) -}} + {%- else -%} + {{- caller(nativetag, None, tagarticles) -}} + {%- endif -%} + {%- endif -%} + {%- endfor -%} +{%- endmacro -%} + +{%- macro article_by_slug(slug, lang) -%} + {%- for a in all_articles -%} + {%- if a.slug == slug and a.lang == lang -%} + {{- caller(a) -}} + {%- endif -%} + {%- endfor -%} +{%- endmacro -%} + +{%- macro page_by_slug(slug, lang) -%} + {%- for p in pages -%} + {%- if p.slug == slug and p.lang == lang -%} + {{- caller(p) -}} + {%- endif -%} + {%- endfor -%} +{%- endmacro -%} + +{%- macro article_or_page_by_slug(slug, lang) -%} + {%- for a in all_articles -%} + {%- if a.slug == slug and a.lang == lang -%} + {{- caller(a, "article") -}} + {%- endif -%} + {%- endfor -%} + {%- for p in pages -%} + {%- if p.slug == slug and p.lang == lang -%} + {{- caller(p, "page") -}} + {%- endif -%} + {%- endfor -%} +{%- endmacro -%} +