gallery: Add per-image caption/title support.

To add caption/title to a picture, in your article simply add a
'gallerycaptions' tag in your metadata, whose value is a dictionnary of
(filename, title) tuples.

Example:
gallery: <Gallery Name>
gallerycaptions: { 'image_name1': 'caption1', 'image_name4': 'caption4', }

Then you will be able to use article.gallerycaptions.get('image_nameX')
in the templates, to retrieve the title associated to the image.
This commit is contained in:
2014-05-29 15:18:22 +02:00
parent 7b3851a62b
commit a8830b8825
2 changed files with 26 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import os
import ast
from pelican import signals
@@ -11,6 +12,7 @@ def add_gallery_post(generator):
if 'gallery' in article.metadata.keys():
album = article.metadata.get('gallery')
galleryimages = []
gallerycaptions = dict()
articlegallerypath=os.path.join(gallerycontentpath, album)
@@ -19,8 +21,12 @@ def add_gallery_post(generator):
if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)):
galleryimages.append(i)
if 'gallerycaptions' in article.metadata.keys():
gallerycaptions = ast.literal_eval(article.metadata.get('gallerycaptions'))
article.album = album
article.galleryimages = sorted(galleryimages)
article.gallerycaptions = gallerycaptions
def generate_gallery_page(generator):