[gimp-web/header-image] Redo random homepage header image



commit 7537229842d88cc87443d41f36bd4717456dca5e
Author: Pat David <patdavid gmail com>
Date:   Thu Jan 19 16:42:02 2017 -0600

    Redo random homepage header image
    
    I redid the randomized header image on the homepage.
    Thanks to drc for the idea to just have the randomization happen
    on build, and to schumaml for actually making that happen every
    hour.
    
    There's now a header-images.json file in the root of the project.
    Add new images to be included in that file - all of the entries
    are mandatory please.
    
    I've pushed the actual randomization and inclusion in the home.css
    to a plugin for Pelican, random_header.  Look there for any
    of that code.
    
    Otherwise the actual setting is now created at the end of the
    pelicanconf* files.  You'll see them there.
    
    Thank you drc and schumaml!

 content/js/rotateHeaderImg.js             |  122 -----------------------------
 header-images.json                        |   17 ++++
 pelicanconf.local.py                      |   18 ++++-
 pelicanconf.py                            |   18 ++++-
 pelicanconf.testing.py                    |   18 ++++-
 plugins/random_header/__init__.py         |    1 +
 plugins/random_header/random_header.py    |   31 +++++++
 themes/newgimp/static/css/home-header.css |    3 -
 themes/newgimp/static/css/home.css        |    1 +
 themes/newgimp/templates/home.html        |   13 +--
 10 files changed, 105 insertions(+), 137 deletions(-)
---
diff --git a/header-images.json b/header-images.json
new file mode 100644
index 0000000..2d64c5d
--- /dev/null
+++ b/header-images.json
@@ -0,0 +1,17 @@
+[
+    {
+        "author": "Ville Pätsi",
+        "authorURL": "http://shadowdrama.net/";,
+        "title": "Niagara Rainbow",
+        "sourceURL": "https://www.flickr.com/photos/shadowdrama/20786243805";,
+        "file": "/images/frontpage/headers/Niagara_Rainbow.jpg",
+        "license": "cc-by-sa"
+    },{
+        "author": "Pat David",
+        "authorURL": "https://pixls.us";,
+        "title": "After the Cotton",
+        "sourceURL": "https://www.flickr.com/photos/patdavid/10614802615";,
+        "file": "/images/frontpage/headers/cotton.jpg",
+        "license": "cc-by-sa"
+    }
+]
diff --git a/pelicanconf.local.py b/pelicanconf.local.py
index 63ed765..32799a7 100644
--- a/pelicanconf.local.py
+++ b/pelicanconf.local.py
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
 
 #Plugins
 PLUGIN_PATHS = ["plugins"]
-PLUGINS = ["mimic_hierarchy", "i18n_subsites", "sitemap", "gimp_mirrors", "tipue_search"]
+PLUGINS = ["mimic_hierarchy", "i18n_subsites", "sitemap", "gimp_mirrors", "tipue_search", "random_header"]
 
 # sitemap plugin settings
 SITEMAP = {
@@ -156,3 +156,19 @@ if 'STABLE' in GIMP:
 else:
     print 'STABLE not defined'
 
+
+#
+# Random Header Background Image
+# 
+# This is to get the possible header images
+# and choose one randomly to display.
+#
+# Templates will use HEADER_IMG data to parse image information.  
+# Refer to the random_header plugin for actually putting the image
+# in the correct stylesheet.
+#
+from random import randint
+with open('header-images.json') as data:
+    IMG_LIST = json.load(data)
+
+HEADER_IMG = IMG_LIST[ randint(0, len(IMG_LIST) - 1) ]
diff --git a/pelicanconf.py b/pelicanconf.py
index cfae844..cfc3235 100644
--- a/pelicanconf.py
+++ b/pelicanconf.py
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
 #Plugins
 PLUGIN_PATHS = ["plugins"]
 #PLUGINS = ["page_hierarchy_gimp"]
-PLUGINS = ["mimic_hierarchy", "i18n_subsites", "sitemap", "gimp_mirrors", "tipue_search"]
+PLUGINS = ["mimic_hierarchy", "i18n_subsites", "sitemap", "gimp_mirrors", "tipue_search", "random_header"]
 
 # sitemap plugin settings
 SITEMAP = {
@@ -156,3 +156,19 @@ if 'STABLE' in GIMP:
 else:
     print 'STABLE not defined'
 
+
+#
+# Random Header Background Image
+# 
+# This is to get the possible header images
+# and choose one randomly to display.
+#
+# Templates will use HEADER_IMG data to parse image information.  
+# Refer to the random_header plugin for actually putting the image
+# in the correct stylesheet.
+#
+from random import randint
+with open('header-images.json') as data:
+    IMG_LIST = json.load(data)
+
+HEADER_IMG = IMG_LIST[ randint(0, len(IMG_LIST) - 1) ]
diff --git a/pelicanconf.testing.py b/pelicanconf.testing.py
index e01dab2..49f5a8b 100644
--- a/pelicanconf.testing.py
+++ b/pelicanconf.testing.py
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
 #Plugins
 PLUGIN_PATHS = ["plugins"]
 #PLUGINS = ["page_hierarchy_gimp"]
-PLUGINS = ["mimic_hierarchy", "i18n_subsites", "sitemap", "gimp_mirrors", "tipue_search"]
+PLUGINS = ["mimic_hierarchy", "i18n_subsites", "sitemap", "gimp_mirrors", "tipue_search", "random_header"]
 
 # sitemap plugin settings
 SITEMAP = {
@@ -156,3 +156,19 @@ if 'STABLE' in GIMP:
 else:
     print 'STABLE not defined'
 
+
+#
+# Random Header Background Image
+# 
+# This is to get the possible header images
+# and choose one randomly to display.
+#
+# Templates will use HEADER_IMG data to parse image information.  
+# Refer to the random_header plugin for actually putting the image
+# in the correct stylesheet.
+#
+from random import randint
+with open('header-images.json') as data:
+    IMG_LIST = json.load(data)
+
+HEADER_IMG = IMG_LIST[ randint(0, len(IMG_LIST) - 1) ]
diff --git a/plugins/random_header/__init__.py b/plugins/random_header/__init__.py
new file mode 100644
index 0000000..2275d36
--- /dev/null
+++ b/plugins/random_header/__init__.py
@@ -0,0 +1 @@
+from .random_header import *
diff --git a/plugins/random_header/random_header.py b/plugins/random_header/random_header.py
new file mode 100644
index 0000000..f18df44
--- /dev/null
+++ b/plugins/random_header/random_header.py
@@ -0,0 +1,31 @@
+from pelican import signals, contents
+import os
+import os.path
+from os.path import basename
+
+
+'''
+Random Header Background Image
+It's been created by me, Pat David, to do what I need for wgo.
+Don't try to make any sense of it.  I don't know what I'm doing.
+I am not kidding.
+'''
+
+class UnexpectedException(Exception): pass
+
+def do_headerimg(pelican):
+
+    HEADER_IMG_STYLE = "#banner { background-image: linear-gradient(rgba(44,52,80,0.5), rgba(44,62,80,0.5)), 
url('"+ pelican.settings['HEADER_IMG']['file'] +"'); }"
+
+    if os.path.exists('./output/theme/css/home.css'):
+        print "Appending banner style to home.css..."
+        with open('./output/theme/css/home.css', 'a') as cssfile:
+            cssfile.write( HEADER_IMG_STYLE )
+    #else:
+    #    print "Appending banner style to home.css..." 
+    #    print "The path doesn't exist? (possibly building i18n - just wait)"
+
+
+def register():
+    signals.finalized.connect(do_headerimg)
+
diff --git a/themes/newgimp/static/css/home.css b/themes/newgimp/static/css/home.css
index 042d8e0..6304149 100644
--- a/themes/newgimp/static/css/home.css
+++ b/themes/newgimp/static/css/home.css
@@ -395,3 +395,4 @@ h2#recent-news {
     margin-bottom: 0;
     text-align: left;
 }
+
diff --git a/themes/newgimp/templates/home.html b/themes/newgimp/templates/home.html
index 15a1cdf..79d0c5a 100644
--- a/themes/newgimp/templates/home.html
+++ b/themes/newgimp/templates/home.html
@@ -244,12 +244,14 @@
         <div class="container">
             <div class="row clearfix">
                 <div class="column half">
+                    {% if HEADER_IMG %}
                     <p id='headerImgAttr'>
-                        <em>Header</em> image: <a class='headerTitle' 
href="https://www.flickr.com/photos/shadowdrama/20786243805/in/dateposted/"; title='Niagara Rainbow'>Niagara 
Rainbow</a> 
+                        <em>Header</em> image: <a class='headerTitle' href="{{ HEADER_IMG.sourceURL }}" 
title='{{ HEADER_IMG.title }}'>{{ HEADER_IMG.title }}</a> 
                         by 
-                        <a class='headerAuthor' href="http://shadowdrama.net/";>Ville Pätsi</a> 
+                        <a class='headerAuthor' href="{{ HEADER_IMG.authorURL }}">{{ HEADER_IMG.author 
}}</a> 
                         (<a class='headerLicense' href="https://creativecommons.org/licenses/by-sa/4.0/"; 
title="Creative Commons Attribution-ShareAlike"><span class='cc'>cba</span></a>)
                     </p>
+                    {% endif %}
 
                     <p>
                         <em>High Quality Photo Manipulation</em> background image by <a 
href="https://pixls.us";>Pat David</a> (<a href="https://creativecommons.org/licenses/by-sa/4.0/"; 
title="Creative Commons Attribution-ShareAlike"><span class='cc'>cba</span></a>)
@@ -274,11 +276,4 @@
         
     </section>
 
-    <noscript>
-    <link rel='stylesheet' type='text/css' href="/theme/css/home-header.css" />
-    </noscript>
-
-    <!-- <script async src='/images/headers.json'></script> -->
-    <script async src='/js/rotateHeaderImg.js'></script>
-
 {% endblock content %}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]