Skip to content

Instantly share code, notes, and snippets.

@inktrap
Last active April 28, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inktrap/bff03f3f8ae6c671115e266c70ec20cb to your computer and use it in GitHub Desktop.
Save inktrap/bff03f3f8ae6c671115e266c70ec20cb to your computer and use it in GitHub Desktop.
Various jinja2 macros used by my port of the uikit theme to pelican.
% some macros for pelican
% limit the number of items you want to display in the sidebar/blogroll list.
% you have to include this in another template as your sidebar
{% macro limit_items(items, name, link, limit, class, line=False, tuple=False) %}
<div class="uk-panel">
<h3 class="uk-panel-title">{{ name | capitalize() }}</h3>
<ul class="uk-list {% if line %}uk-list-line{% endif %}">
{% if limit == 0 %}
{% set limit = items|length %}
{% endif %}
{% for item in items %}
{% if (limit > 0) and (loop.index > limit) %}
<li class="uk-hidden hidden-{{ name }}"><a href="{% if tuple %}{{item.1}}{% else %}/{{ item.0.url }}{% endif %}" class="{{ class }}">{% if tuple %}{{ item.0 }}{% else %}{{ item.0.name }}{% endif %}</a></li>
{% if loop.last %}
</ul>
<button class="uk-button hidden-{{ name }}" data-uk-toggle="{target:'.hidden-{{ name }}'}">More {{ name | capitalize() }}</button>
<button class="uk-hidden uk-button hidden-{{ name }}" data-uk-toggle="{target:'.hidden-{{ name }}'}">Less {{ name | capitalize() }}</button>
{% endif %}
{% else %}
<li><a href="{% if tuple %}{{ item.1 }}{% else %}/{{ item.0.url }}{% endif %}" class="{{ class }}">{% if tuple %}{{ item.0 }}{% else %}{{ item.0.name }}{% endif %}</a></li>
{% if (loop.last) %}
</ul>
{% endif %}
{% endif %}
{% endfor %}
</div>
{% endmacro %}
<div class="uk-panel uk-panel-box uk-text-center">
<a href="/author/{{AUTHOR}}.html">
<img alt="A picture of the author of this content." class="uk-border-circle" src="/theme/img/{{AUTHOR_IMAGE}}"/><h3>{{AUTHOR}}</h3></a>
<p>
Hi there! My name is {{AUTHOR_REAL}}, check out more <a href="{{MOREABOUTMEURL}}">about me</a>.
</p>
</div>
<div class="uk-panel">
<h3 class="uk-panel-title">Social Links</h3>
<div class="icons">
{% for name, link in SOCIAL %}
<a href="{{ link }}" class="uk-icon-button uk-icon-justify uk-icon-{{name}}"></a>
{% endfor %}
</div>
</div>
{% if DISPLAY_TAGS_ON_SIDEBAR_LIMIT >= 0 %}
{{ limit_items(tags, 'tags', SITEURL ~ '/tag/', DISPLAY_TAGS_ON_SIDEBAR_LIMIT, 'uk-icon-tag', True, False) }}
{% endif %}
{% if DISPLAY_LINKS_ON_SIDEBAR_LIMIT >= 0 %}
{{ limit_items(LINKS, 'links', '', DISPLAY_LINKS_ON_SIDEBAR_LIMIT, 'uk-icon-external-link', True, True) }}
{% endif %}
% display a cc license and host the icons either yourself or use a hosted version. can be compact/not and/or brief/not.
% you have to import and call the macro
{% macro license(SITEURL, LICENSE={'cc_name':'by', 'hosted':False, 'compact':True, 'brief':True}) %}
{% set cc_name = LICENSE['cc_name']|lower|trim|replace("cc-","") %}
{% if LICENSE['compact'] %}
{% set cc_size = "80x15" -%}
{% else %}
{% set cc_size = "88x31" -%}
{% endif %}
{% if not LICENSE['hosted'] %}
{% set cc_icon = [SITEURL|lower|trim,
"/theme/ico/cc/",
cc_name,
"/4.0/",
cc_size,
".png"
]|join("")
%}
{% else %}
{% set cc_icon = ["https://licensebuttons.net/l/",
cc_name,
"/4.0/",
cc_size,
".png"
]|join("")
%}
{% endif %}
{% set cc_title = ["Creative Commons Attribution 4.0 International",
cc_name|upper,
" License"
]|join("")
%}
{% set cc_uri = ["http://creativecommons.org/licenses/",
cc_name,
"/4.0/"
]|join("")
%}
{% if not LICENSE['brief'] %}
{% set cc_intro = "This work is licensed under a " %}
{% set cc_linktext = "Creative Commons CC_NAME 4.0 International License"|replace("CC_NAME", cc_name|upper, 1) %}
{% else %}
{% set cc_intro = "" %}
{% set cc_intro = "License " %}
{% set cc_linktext = "CC_NAME 4.0 "|replace("CC_NAME", cc_name|upper, 1) %}
{% endif %}
{% set license = [
'<a class="license" rel="license" href="http://creativecommons.org/licenses/CC_NAME/4.0/">',
'<img alt="Creative Commons License" style="border-width:0" src="CC_ICON" /></a>'|replace("CC_ICON", cc_icon|trim),
cc_intro,
'<a class="license" rel="license" href="http://creativecommons.org/licenses/CC_NAME/4.0/">',
cc_linktext,
'</a>'
] | join("") %}
{{ license|replace("CC_NAME", cc_name,2)|trim }}
{% endmacro %}
% gives an article objects a date.
% you have to import and call the macro
{% macro get_time(article, date) -%}
{% set datetime = date|strftime('%Y-%m-%d') %}
<time datetime="{{datetime}}">{{ article.locale_date|trim }}</time>
{%- endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment