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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user