Merge pull request #125 from XenGi/patch-1
Sort images by filename in Gallery plugin
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
|
|
||||||
|
|
||||||
def add_gallery_post(generator):
|
def add_gallery_post(generator):
|
||||||
|
|
||||||
contentpath = generator.settings.get('PATH')
|
contentpath = generator.settings.get('PATH')
|
||||||
gallerycontentpath = os.path.join(contentpath,'images/gallery')
|
gallerycontentpath = os.path.join(contentpath,'images/gallery')
|
||||||
|
|
||||||
|
|
||||||
for article in generator.articles:
|
for article in generator.articles:
|
||||||
if 'gallery' in article.metadata.keys():
|
if 'gallery' in article.metadata.keys():
|
||||||
album = article.metadata.get('gallery')
|
album = article.metadata.get('gallery')
|
||||||
@@ -19,9 +19,8 @@ def add_gallery_post(generator):
|
|||||||
if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)):
|
if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)):
|
||||||
galleryimages.append(i)
|
galleryimages.append(i)
|
||||||
|
|
||||||
article.album=album
|
article.album = album
|
||||||
article.galleryimages=galleryimages
|
article.galleryimages = sorted(galleryimages)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generate_gallery_page(generator):
|
def generate_gallery_page(generator):
|
||||||
@@ -29,10 +28,9 @@ def generate_gallery_page(generator):
|
|||||||
contentpath = generator.settings.get('PATH')
|
contentpath = generator.settings.get('PATH')
|
||||||
gallerycontentpath = os.path.join(contentpath,'images/gallery')
|
gallerycontentpath = os.path.join(contentpath,'images/gallery')
|
||||||
|
|
||||||
|
|
||||||
for page in generator.pages:
|
for page in generator.pages:
|
||||||
if page.metadata.get('template') == 'gallery':
|
if page.metadata.get('template') == 'gallery':
|
||||||
gallery=dict()
|
gallery = dict()
|
||||||
|
|
||||||
for a in os.listdir(gallerycontentpath):
|
for a in os.listdir(gallerycontentpath):
|
||||||
if os.path.isdir(os.path.join(gallerycontentpath, a)):
|
if os.path.isdir(os.path.join(gallerycontentpath, a)):
|
||||||
@@ -40,11 +38,11 @@ def generate_gallery_page(generator):
|
|||||||
for i in os.listdir(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)):
|
if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, a), i)):
|
||||||
gallery.setdefault(a, []).append(i)
|
gallery.setdefault(a, []).append(i)
|
||||||
|
gallery[a].sort()
|
||||||
|
|
||||||
page.gallery=gallery
|
page.gallery=gallery
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
signals.article_generator_finalized.connect(add_gallery_post)
|
signals.article_generator_finalized.connect(add_gallery_post)
|
||||||
signals.page_generator_finalized.connect(generate_gallery_page)
|
signals.page_generator_finalized.connect(generate_gallery_page)
|
||||||
|
|||||||
Reference in New Issue
Block a user