From 7b26ad1013bb27318f18121a41d267ade2b95f06 Mon Sep 17 00:00:00 2001 From: Arul Date: Mon, 14 May 2018 13:26:35 +0530 Subject: [PATCH] Header fixes (#25) * #21 changing logic to selecting cover image - For categories, tags - Some code refactor and indenting * #21 initial codes for pelican unit tests * #21 few more testing changes * Ref #21 unit tests for article tests coverimages * Ref #21 unit tests for page, tags, category and author coverimages * Ref #21 readme updated --- README.adoc | 83 ++- templates/archives.html | 20 +- templates/article.html | 80 +-- templates/author.html | 50 +- templates/authors.html | 21 +- templates/categories.html | 20 +- templates/category.html | 30 +- templates/index.html | 25 +- templates/page.html | 36 +- templates/tag.html | 30 +- templates/tags.html | 24 +- tests/__init__.py | 0 tests/content/article_with_cover_image.rst | 7 + .../content/article_with_http_cover_image.rst | 7 + tests/content/article_with_og_image.rst | 7 + tests/content/article_without_cover.rst | 6 + tests/content/assets/css/myblog.css | 0 tests/content/assets/favicon.ico | 0 tests/content/assets/images/article_cover.jpg | 1 + .../assets/images/arul_author_cover.jpg | 1 + tests/content/assets/images/avatar.png | Bin 0 -> 3684 bytes .../assets/images/bar_category_cover.jpg | 1 + tests/content/assets/images/bar_tag_cover.jpg | 1 + tests/content/assets/images/cover.jpg | Bin 0 -> 26162 bytes .../assets/images/foo_category_cover.jpg | 1 + tests/content/assets/images/foo_tag_cover.jpg | 1 + tests/content/assets/images/header_cover.jpg | 1 + tests/content/assets/images/og_cover.jpg | 1 + tests/content/assets/images/page_cover.jpg | 1 + .../assets/images/raj_author_cover.jpg | 1 + tests/content/assets/robots.txt | 0 tests/content/pages/page_with_cover_image.rst | 7 + .../pages/page_with_http_cover_image.rst | 7 + tests/content/pages/page_with_og_image.rst | 7 + .../pages/page_without_cover_image.rst | 6 + tests/default_conf.py | 126 ++++ tests/support.py | 218 +++++++ tests/test_coverimages.py | 580 ++++++++++++++++++ tests/unittest.cfg | 3 + 39 files changed, 1283 insertions(+), 127 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/content/article_with_cover_image.rst create mode 100644 tests/content/article_with_http_cover_image.rst create mode 100644 tests/content/article_with_og_image.rst create mode 100644 tests/content/article_without_cover.rst create mode 100644 tests/content/assets/css/myblog.css create mode 100644 tests/content/assets/favicon.ico create mode 120000 tests/content/assets/images/article_cover.jpg create mode 120000 tests/content/assets/images/arul_author_cover.jpg create mode 100644 tests/content/assets/images/avatar.png create mode 120000 tests/content/assets/images/bar_category_cover.jpg create mode 120000 tests/content/assets/images/bar_tag_cover.jpg create mode 100644 tests/content/assets/images/cover.jpg create mode 120000 tests/content/assets/images/foo_category_cover.jpg create mode 120000 tests/content/assets/images/foo_tag_cover.jpg create mode 120000 tests/content/assets/images/header_cover.jpg create mode 120000 tests/content/assets/images/og_cover.jpg create mode 120000 tests/content/assets/images/page_cover.jpg create mode 120000 tests/content/assets/images/raj_author_cover.jpg create mode 100644 tests/content/assets/robots.txt create mode 100644 tests/content/pages/page_with_cover_image.rst create mode 100644 tests/content/pages/page_with_http_cover_image.rst create mode 100644 tests/content/pages/page_with_og_image.rst create mode 100644 tests/content/pages/page_without_cover_image.rst create mode 100644 tests/default_conf.py create mode 100644 tests/support.py create mode 100644 tests/test_coverimages.py create mode 100644 tests/unittest.cfg diff --git a/README.adoc b/README.adoc index 60acb21..109cd28 100644 --- a/README.adoc +++ b/README.adoc @@ -74,33 +74,96 @@ Here are all configurations about this theme. [[header-covers]] === Header Covers -To define custom header cover, set the property `HEADER_COVER` in +You can set cover images for your blog, article, page, tag, category and author. The cover images can be from your relative path or from internet. + +[[blog-cover]] +==== Blog Cover + +The is the cover image for your site main index.html. + +To set blog cover, set the property `HEADER_COVER` in `pelicanconf.py`: [source,python] ---- -HEADER_COVER = 'static/my_image.png' +HEADER_COVER = '/assets/images/blog_cover.png' ---- -This is site level cover image and it will be used If there is no cover -image set in link:#articles[article] level. +[[article-cover]] +==== Article Cover -[[header-color]] +To set different cover image for an article set `cover` metadata in front-matter. -==== Custom Header Covers +[source,python] +---- +:title: With Cover Images +:date: 2018-04-29 00:45 +:author: arul +:category: foo +:tags: footag +:slug: with-cover-images +:cover: /assets/images/article_cover.jpg +---- -For each page, category page, tag page or author page you can set a custom header cover. -To define it, just set the following properties in `pelicanconf.py` +For more refer link:#articles[article] . -Use the page title as defined in metadata for the pages +[[page-cover]] +==== Page Cover + +To set different cover image for a page set `cover` metadata in front-matter. + +[source,python] +---- +:title: Page With Cover Images +:date: 2018-04-29 00:45 +:author: arul +:category: foo +:tags: footag +:slug: page-with-cover-images +:cover: assets/images/page_cover.jpg +---- + +For more refer link:#articles[article] . + +[[tag-cover]] +==== Tag Cover + +To set cover image for a tag, set the property `HEADER_COVERS_BY_TAG` in +`pelicanconf.py`: [source,python] ---- HEADER_COVERS_BY_TAG = {'food': '/images/food.png', 'drinks':'/images/orange-juice.png'} +---- + +[[category-cover]] +==== Category Cover + +To set cover image for a category, set the property `HEADER_COVERS_BY_CATEGORY` in +`pelicanconf.py`: + +[source,python] +---- HEADER_COVERS_BY_CATEGORY = {'food': '/images/junkie-stuff.png'} ---- +[[author-cover]] +==== Author Cover +To set cover image for an author, set the property `AUTHORS_BIO` in `pelicanconf.py`: + +[source,python] +---- +AUTHORS_BIO = { + "zutrinken": { + "cover": "/assets/images/zutrinken-cover.png" + } +} +---- + +For more refer link:#author-bio[author] . + +[[header-color]] === Header Color To define a simple header background color, set the property @@ -114,6 +177,8 @@ HEADER_COLOR = 'black' you can use any valid css color. This will be used if there is no cover image set in link:#articles[article] level and site level. +This property will be used if there is no cover image set to an article, page, tag, category, author. + [[social-urls]] === Social URLs diff --git a/templates/archives.html b/templates/archives.html index 58bd4b7..439ef12 100644 --- a/templates/archives.html +++ b/templates/archives.html @@ -2,6 +2,16 @@ {% block title %}{{ SITENAME }} - Archives{% endblock %} +{% if HEADER_COVER %} + {% if HEADER_COVER|lower|truncate(4, True, '') == "http" %} + {% set selected_cover = HEADER_COVER %} + {% else %} + {% set selected_cover = SITEURL+"/"+HEADER_COVER %} + {% endif %} +{% elif HEADER_COLOR %} + {% set selected_color = HEADER_COLOR %} +{% endif %} + {% block header %} @@ -22,12 +32,12 @@

{{ SITENAME }} - Archives

- {% if HEADER_COVER %} -
- {% elif HEADER_COLOR %} -
+ {% if selected_cover %} +
+ {% elif selected_color %} +
{% else %} -
+
{% endif %}
diff --git a/templates/article.html b/templates/article.html index 525e582..80e6987 100644 --- a/templates/article.html +++ b/templates/article.html @@ -3,53 +3,53 @@ {# #} {% if article.cover %} - {% if article.cover|lower|truncate(4, True, '') == "http" %} - {% set default_cover = article.cover %} - {% else %} - {% set default_cover = SITEURL+"/"+article.cover %} - {% endif %} + {% if article.cover|lower|truncate(4, True, '') == "http" %} + {% set selected_cover = article.cover %} + {% else %} + {% set selected_cover = SITEURL+"/"+article.cover %} + {% endif %} {% elif article.og_image %} - {% if article.og_image|lower|truncate(4, True, '') == "http" %} - {% set default_cover = article.og_image %} - {% else %} - {% set default_cover = SITEURL+"/"+article.og_image %} - {% endif %} + {% if article.og_image|lower|truncate(4, True, '') == "http" %} + {% set selected_cover = article.og_image %} + {% else %} + {% set selected_cover = SITEURL+"/"+article.og_image %} + {% endif %} {% elif HEADER_COVER %} - {% set default_cover = SITEURL+"/"+HEADER_COVER %} -{% endif %} - -{% if article.color %} - {% set default_color = article.color %} + {% if HEADER_COVER|lower|truncate(4, True, '') == "http" %} + {% set selected_cover = HEADER_COVER %} + {% else %} + {% set selected_cover = SITEURL+"/"+HEADER_COVER %} + {% endif %} {% elif HEADER_COLOR %} - {% set default_color = HEADER_COLOR %} + {% set selected_color = HEADER_COLOR %} {% endif %} {% block head %} - {{ super() }} + {{ super() }} - - {% for keyword in article.keywords %} - - {% endfor %} + + {% for keyword in article.keywords %} + + {% endfor %} - {% if description %} - - {% elif article.headline %} - - {% elif article.summary %} - - {% endif %} + {% if description %} + + {% elif article.headline %} + + {% elif article.summary %} + + {% endif %} - {% for author in article.authors %} - - {% endfor %} + {% for author in article.authors %} + + {% endfor %} - {% for tag in article.tags %} - - {% endfor %} + {% for tag in article.tags %} + + {% endfor %} - {% include 'partials/og_article.html' %} - {% include 'partials/jsonld_article.html' %} + {% include 'partials/og_article.html' %} + {% include 'partials/jsonld_article.html' %} {% endblock %} {% block header %} @@ -95,10 +95,10 @@ {% if article.modified %} {% endif %} - {% if default_cover %} -
- {% elif default_color %} -
+ {% if selected_cover %} +
+ {% elif selected_color %} +
{% else %}
{% endif %} diff --git a/templates/author.html b/templates/author.html index 4a53733..51a9415 100644 --- a/templates/author.html +++ b/templates/author.html @@ -3,21 +3,33 @@ {% set author_name = author.name | title %} {% if AUTHORS_BIO and author.name.lower() in AUTHORS_BIO %} - {% set author_avatar = AUTHORS_BIO[author.name.lower()].image %} - {% if author_avatar %} - {% if author_avatar|lower|truncate(4, True, '') != "http" %} - {% set author_avatar = SITEURL+"/"+author_avatar %} - {% endif %} + {% set author_avatar = AUTHORS_BIO[author.name.lower()].image %} + {% if author_avatar %} + {% if author_avatar|lower|truncate(4, True, '') == "http" %} + {% set selected_avatar = author_avatar %} + {% else %} + {% set selected_avatar = SITEURL+"/"+author_avatar %} {% endif %} + {% endif %} - {% set author_cover = AUTHORS_BIO[author.name.lower()].cover %} - {% if author_cover %} - {% if author_cover|lower|truncate(4, True, '') != "http" %} - {% set author_cover= SITEURL+"/"+author_cover %} - {% endif %} + {% set author_cover = AUTHORS_BIO[author.name.lower()].cover %} + {% if author_cover %} + {% if author_cover|lower|truncate(4, True, '') == "http" %} + {% set selected_cover = author_cover %} + {% else %} + {% set selected_cover = SITEURL+"/"+author_cover %} {% endif %} + {% endif %} - {% set author_name = AUTHORS_BIO[author.name.lower()].name or author.name %} + {% set author_name = AUTHORS_BIO[author.name.lower()].name or author.name %} +{% elif HEADER_COVER %} + {% if HEADER_COVER|lower|truncate(4, True, '') == "http" %} + {% set selected_cover = HEADER_COVER %} + {% else %} + {% set selected_cover = SITEURL+"/"+HEADER_COVER %} + {% endif %} +{% elif HEADER_COLOR %} + {% set selected_color = HEADER_COLOR %} {% endif %} {% block title %}{{ SITENAME }} - Articles by {{ author_name }}{% endblock %} @@ -50,14 +62,12 @@ Menu - {% if AUTHORS_BIO and author.name.lower() in AUTHORS_BIO and author_cover %} -
- {% elif HEADER_COVER %} -
- {% elif HEADER_COLOR %} -
+ {% if selected_cover %} +
+ {% elif selected_color %} +
{% else %} -
+
{% endif %}
@@ -66,9 +76,9 @@