Last active
April 28, 2016 16:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% some macros for pelican |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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