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:
@@ -17,6 +17,10 @@ Attach an album to an article/post by placing a gallery metadata tag with the na
|
|||||||
|
|
||||||
gallery:album_name
|
gallery:album_name
|
||||||
|
|
||||||
|
Optionaly you can also add (on one(1) line!)
|
||||||
|
|
||||||
|
gallerycaptions:{'file1':'title1', 'file4':'title4'}
|
||||||
|
|
||||||
The template has access to the album name.
|
The template has access to the album name.
|
||||||
|
|
||||||
article.album
|
article.album
|
||||||
@@ -25,6 +29,10 @@ And the filename of images within an album.
|
|||||||
|
|
||||||
article.albumimages
|
article.albumimages
|
||||||
|
|
||||||
|
And the titles associated to the pictures, as a dictionary.
|
||||||
|
|
||||||
|
article.gallerycaptions
|
||||||
|
|
||||||
###Gallery Page
|
###Gallery Page
|
||||||
|
|
||||||
Create a page and a gallery template (named gallery.html). And inform pelican to use the gallery template for the page.
|
Create a page and a gallery template (named gallery.html). And inform pelican to use the gallery template for the page.
|
||||||
@@ -43,7 +51,11 @@ The dictionary key is the name of the album and the lists contain the filenames.
|
|||||||
<h2><a href="{{ SITEURL }}/pages/gallery.html#{{ article.album }}">{{ article.album }}</a></h2>
|
<h2><a href="{{ SITEURL }}/pages/gallery.html#{{ article.album }}">{{ article.album }}</a></h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% for image in article.galleryimages %}
|
{% for image in article.galleryimages %}
|
||||||
|
{% if article.gallerycaptions.get(image) %}
|
||||||
|
<li><a class="{{ article.album }} cboxElement" href="{{ SITEURL }}/static/images/gallery/{{ article.album }}/{{ image }}" title="{{ article.gallerycaptions.get(image) }}">{{ article.gallerycaptions.get(image) }}<br><img src="{{ SITEURL }}/static/images/gallery200x200/{{ article.album }}/{{ image }}"></a></li>
|
||||||
|
{% else %}
|
||||||
<li><a class="{{ article.album }} cboxElement" href="{{ SITEURL }}/static/images/gallery/{{ article.album }}/{{ image }}"><img src="{{ SITEURL }}/static/images/gallery200x200/{{ article.album }}/{{ image }}"></a></li>
|
<li><a class="{{ article.album }} cboxElement" href="{{ SITEURL }}/static/images/gallery/{{ article.album }}/{{ image }}"><img src="{{ SITEURL }}/static/images/gallery200x200/{{ article.album }}/{{ image }}"></a></li>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@@ -63,6 +75,12 @@ The dictionary key is the name of the album and the lists contain the filenames.
|
|||||||
title:Foo
|
title:Foo
|
||||||
gallery:albumname
|
gallery:albumname
|
||||||
|
|
||||||
|
or, to add captions:
|
||||||
|
|
||||||
|
title:Foo
|
||||||
|
gallery:albumname
|
||||||
|
gallerycaptions:{'file1':'title1', 'file4':'title4'}
|
||||||
|
|
||||||
###pages/gallery.md
|
###pages/gallery.md
|
||||||
|
|
||||||
title:All Images
|
title:All Images
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import ast
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
|
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ def add_gallery_post(generator):
|
|||||||
if 'gallery' in article.metadata.keys():
|
if 'gallery' in article.metadata.keys():
|
||||||
album = article.metadata.get('gallery')
|
album = article.metadata.get('gallery')
|
||||||
galleryimages = []
|
galleryimages = []
|
||||||
|
gallerycaptions = dict()
|
||||||
|
|
||||||
articlegallerypath=os.path.join(gallerycontentpath, album)
|
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)):
|
if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)):
|
||||||
galleryimages.append(i)
|
galleryimages.append(i)
|
||||||
|
|
||||||
|
if 'gallerycaptions' in article.metadata.keys():
|
||||||
|
gallerycaptions = ast.literal_eval(article.metadata.get('gallerycaptions'))
|
||||||
|
|
||||||
article.album = album
|
article.album = album
|
||||||
article.galleryimages = sorted(galleryimages)
|
article.galleryimages = sorted(galleryimages)
|
||||||
|
article.gallerycaptions = gallerycaptions
|
||||||
|
|
||||||
|
|
||||||
def generate_gallery_page(generator):
|
def generate_gallery_page(generator):
|
||||||
|
|||||||
Reference in New Issue
Block a user