From c1e67fef8bf81a5f869fa18251c62ba433d5e2f7 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 19 Jan 2017 18:30:07 +0000 Subject: [PATCH] Add get image helper --- pelicanconf.py | 3 ++- plugins/filters.py | 4 ++++ theme/templates/extras/header.html | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index 17e444f..e3e5a2f 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -110,7 +110,8 @@ JINJA_FILTERS = { "category_find": filters.category_find, "limit": filters.limit, "get_title": filters.get_title, - "get_html_title": filters.get_html_title + "get_html_title": filters.get_html_title, + "get_image": filters.get_image } JINJA_ENVIRONMENT = { diff --git a/plugins/filters.py b/plugins/filters.py index b52296f..a01acad 100644 --- a/plugins/filters.py +++ b/plugins/filters.py @@ -31,3 +31,7 @@ def get_title(instance): def get_html_title(instance): return get_attribute(instance, 'html_title') or get_title(instance) + + +def get_image(instance): + return get_attribute(instance, 'image') or (hasattr(instance, 'page') and get_attribute(instance.page, 'name')) or '' diff --git a/theme/templates/extras/header.html b/theme/templates/extras/header.html index d590185..93dc8de 100644 --- a/theme/templates/extras/header.html +++ b/theme/templates/extras/header.html @@ -1,4 +1,4 @@ -