From dacc64023d8c094710bd52df029629b96dd24aba Mon Sep 17 00:00:00 2001 From: Ricardo Band Date: Tue, 7 Jan 2014 21:16:06 +0100 Subject: [PATCH] added sorting of images The images are now sorted by their filename. --- gallery/gallery.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/gallery/gallery.py b/gallery/gallery.py index 83ff7750d..3bde1c5b1 100644 --- a/gallery/gallery.py +++ b/gallery/gallery.py @@ -1,48 +1,46 @@ import os from pelican import signals + def add_gallery_post(generator): - contentpath = generator.settings.get('PATH') + contentpath = generator.settings.get('PATH') gallerycontentpath = os.path.join(contentpath,'images/gallery') - - + for article in generator.articles: if 'gallery' in article.metadata.keys(): album = article.metadata.get('gallery') galleryimages = [] - + articlegallerypath=os.path.join(gallerycontentpath, album) - - if(os.path.isdir(articlegallerypath)): + + if(os.path.isdir(articlegallerypath)): for i in os.listdir(articlegallerypath): if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)): galleryimages.append(i) - - article.album=album - article.galleryimages=galleryimages + article.album = album + article.galleryimages = sorted(galleryimages) def generate_gallery_page(generator): - contentpath = generator.settings.get('PATH') + contentpath = generator.settings.get('PATH') gallerycontentpath = os.path.join(contentpath,'images/gallery') - - + for page in generator.pages: if page.metadata.get('template') == 'gallery': - gallery=dict() - + gallery = dict() + for a in os.listdir(gallerycontentpath): if os.path.isdir(os.path.join(gallerycontentpath, a)): - + for i in os.listdir(os.path.join(gallerycontentpath, a)): if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, a), i)): gallery.setdefault(a, []).append(i) - - page.gallery=gallery + gallery[a].sort() + page.gallery=gallery def register():