123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- """
- Copyright (c) Emmet McPoland <emcpoland@gmail.com>
- Gallery
- ==================
- * Allows an article to contain an album of pictures.
- * All albums can also be syndicated into a central gallery page.
- ##How to Use
- 1. Group images into folders, with each folder representing an album.
- 2. Place all album folders within a folder named gallery, which resides within the images folder.
- ./content/images/gallery/album_name
-
- ###Articles
- Attach an album to an article/post by placing a gallery stub with the name of the album.
- gallery:album_name
-
- The template has access to the album name.
- article.album
- And the filename of images within an album.
- article.albumimages
- ###Gallery Page
- Create a page and a gallery template (named gallery.html). And inform pelican to use the gallery template for the page.
- template:gallery
-
- The template has access to a dictionary of lists.
- The dictionary key is the name of the album and the lists contain the filenames.
- page.gallery
-
- ##Examples
- ###article.html
- {% for album, images in page.gallery.iteritems() %}
- <h2><a href="{{ SITEURL }}/pages/gallery.html#{{ article.album }}">{{ article.album }}</a></h2>
- <ul>
- {% for image in article.galleryimages %}
- <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>
- {% endfor %}
- </ul>
- {% endfor %}
-
- ###gallery.html
- {% for album, images in page.gallery.iteritems() %}
- <h2><a name="{{ album }}">{{ album }}</a></h2>
- <ul>
- {% for image in images %}
- <li><a class="{{ album }} cboxElement" href="{{ SITEURL }}/static/images/gallery/{{album}}/{{ image }}" title="{{ image }}"><img src="{{ SITEURL }}/static/images/gallery200x200/{{album}}/{{ image }}"></a></li>
- {% endfor %}
- </ul>
- {% endfor %}
- ###posts/foo.md
- title:Foo
- gallery:albumname
-
- ###pages/gallery.md
- title:All Images
- template:gallery
-
- ##Reasoning
- The album name and filenames are returned as opposed to the direct path to the images,
- to allow flexibility of different thumbnail sizes to be used it different locations of a website.
- href="{{ SITEURL }}/static/images/gallery/{{album}}/{{ image }}"
- href="{{ SITEURL }}/static/images/gallery200x200/{{album}}/{{ image }}"
-
- It also allows a thumbnail to link to the full image,
- as well as the filename extension to be stripped and the title of an image to be displayed along side the title of an album.
- ##Recommendation
- It is recommended to use this extension along with the thumbnailer plugin.
- RESIZE = [
- ('gallery', False, 200,200),
- ]
- You may also wish to use this along with a gallery plugin such as [Colorbox](http://www.jacklmoore.com/colorbox/).
- ##In Use
- * [SESIF Article](http://sesif.github.io/my-super-title.html)
- * [SESIF Gallery](http://sesif.github.io/pages/gallery.html)
- * [SESIF Source](http://github.com/SESIF/SESIF.github.io/tree/source)
- """
- import os
- from pelican import signals
- __author__ = "Emmet McPoland"
- def add_gallery_post(generator):
- 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)):
- 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
- def generate_gallery_page(generator):
- 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()
-
- 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
- def register():
- signals.article_generator_finalized.connect(add_gallery_post)
- signals.pages_generator_finalized.connect(generate_gallery_page)
|