cc-license.html 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. {# ------------------------------------------------------------------------ #}
  2. {# Creative Commons license mark generator for Jinja2 templates, including #}
  3. {# Pelican-generated static sites (or blogs). #}
  4. {# ------------------------------------------------------------------------ #}
  5. {# To use, put this file in a location where your template can import it. #}
  6. {# Then import into the template, for example like this: #}
  7. {# {% from '/path/to/where/you/placed/the/file' import cc_license_mark %} #}
  8. {# Then call as simply as {{ cc_license_mark("CC-BY") }}. #}
  9. {# #}
  10. {# If full attribution markup is desired in a Pelican template, the #}
  11. {# attr_props dict can be defaulted to the following when calling the macro:#}
  12. {# attr_props={'title':SITENAME,'name':AUTHOR,'url':SITEURL}
  13. {# ------------------------------------------------------------------------ #}
  14. {# Generate a license mark for Creative Commons licensed content. #}
  15. {# Choose the license either by name (CC-BY, CC-BY-SA, CC-BY-NC-SA, or #}
  16. {# CC-BY-NC-ND), or by its features (allow derivatives: Yes, No, ShareAlike;#}
  17. {# allow commercial reuse: Yes, No). Name, if provided, takes precedence, #}
  18. {# and case is ignored. #}
  19. {# #}
  20. {# Optional: #}
  21. {# br_after_icon: if true put a line break after the license icon #}
  22. {# attr_markup: if true create markup for fulll attribution #}
  23. {# attr_props: if attr_markup, a dict with title, name, and url keys #}
  24. {# specifying how under which title, to which creator, and #}
  25. {# to which URL to attribute the work #}
  26. {# The parameters all mirror the Creative Commone license chooser: #}
  27. {# http://creativecommons.org/choose/ #}
  28. {# ------------------------------------------------------------------------ #}
  29. {# Copyright (c) 1994 Hilmar Lapp, hlapp@drycafe.net. #}
  30. {# Licensed under the terms of the MIT License. #}
  31. {# Source at http://github.com/hlapp/cc-tools. Please fork & contribute. #}
  32. {# ------------------------------------------------------------------------ #}
  33. {% macro cc_license_mark(cc_name,
  34. derivatives, commercial,
  35. br_after_icon=false,
  36. attr_markup=false,
  37. attr_props={}) %}
  38. {% if cc_name %}
  39. {% set cc_name = cc_name|lower|replace("cc-","") %}
  40. {% set cc_title_suffix = cc_name|replace("by", "")|replace("-nc","-NonCommercial")|replace("-nd","-NoDerivatives")|replace("-sa","-ShareAlike") %}
  41. {% else %}
  42. {% set cc_name = "by" %}
  43. {% set cc_title_suffix = "" %}
  44. {% if (not commercial) or (commercial|lower == "no") %}
  45. {% set cc_name = cc_name ~ "-nc" %}
  46. {% set cc_title_suffix = "-NonCommercial" %}
  47. {% endif %}
  48. {% if derivatives|lower == "no" %}
  49. {% set cc_name = cc_name ~ "-nd" %}
  50. {% set cc_title_suffix = cc_title_suffix ~ "-NoDerivatives" %}
  51. {% elif derivatives|lower == "sharealike" %}
  52. {% set cc_name = cc_name ~ "-sa" %}
  53. {% set cc_title_suffix = cc_title_suffix ~ "-ShareAlike" %}
  54. {% endif %}
  55. {% endif %}
  56. {% set cc_title, cc_uri, cc_icon = ("Creative Commons AttributionCCSUFFIX 4.0 International License","http://creativecommons.org/licenses/CCNAME/4.0/","//i.creativecommons.org/l/CCNAME/4.0/80x15.png") %}
  57. <a rel="license" href="{{ cc_uri|replace('CCNAME',cc_name) }}"><img alt="Creative Commons License" style="border-width:0" src="{{ cc_icon|replace('CCNAME',cc_name) }}" /></a>
  58. {% if br_after_img %}<br/>{% endif %}
  59. {% if attr_markup %}
  60. &quot;<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">{{ attr_props['title'] }}</span>&quot; by <a xmlns:cc="http://creativecommons.org/ns#" href="{{ attr_props['url'] }}" property="cc:attributionName" rel="cc:attributionURL">{{ attr_props['name'] }}</a> is
  61. {% else %}
  62. {% endif %}
  63. {% endmacro %}