From fec36746b32181f73d8e54fd199290ebe1a9df97 Mon Sep 17 00:00:00 2001 From: Emmet McPoland Date: Thu, 11 Apr 2013 12:53:24 +0100 Subject: [PATCH 1/2] Initial Gallery Plugin Commit --- pelicanext/gallery/README.md | 98 +++++++++++++++++++++ pelicanext/gallery/gallery.py | 156 ++++++++++++++++++++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 pelicanext/gallery/README.md create mode 100644 pelicanext/gallery/gallery.py diff --git a/pelicanext/gallery/README.md b/pelicanext/gallery/README.md new file mode 100644 index 0000000..e07045c --- /dev/null +++ b/pelicanext/gallery/README.md @@ -0,0 +1,98 @@ +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() %} +

{{ article.album }}

+ + {% endfor %} + +###gallery.html + + {% for album, images in page.gallery.iteritems() %} +

{{ album }}

+ + {% 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) diff --git a/pelicanext/gallery/gallery.py b/pelicanext/gallery/gallery.py new file mode 100644 index 0000000..35c6052 --- /dev/null +++ b/pelicanext/gallery/gallery.py @@ -0,0 +1,156 @@ +""" +Copyright (c) Emmet McPoland + +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() %} +

{{ article.album }}

+ + {% endfor %} + +###gallery.html + + {% for album, images in page.gallery.iteritems() %} +

{{ album }}

+ + {% 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) From 3df9768a04d718c54f4ff6f8983982e4b6b138ef Mon Sep 17 00:00:00 2001 From: Emmet McPoland Date: Fri, 24 May 2013 01:42:26 +0000 Subject: [PATCH 2/2] Removed Docstring clarified stub --- pelicanext/gallery/README.md | 2 +- pelicanext/gallery/gallery.py | 106 ---------------------------------- 2 files changed, 1 insertion(+), 107 deletions(-) diff --git a/pelicanext/gallery/README.md b/pelicanext/gallery/README.md index e07045c..8cac9ac 100644 --- a/pelicanext/gallery/README.md +++ b/pelicanext/gallery/README.md @@ -13,7 +13,7 @@ Gallery ###Articles -Attach an album to an article/post by placing a gallery stub with the name of the album. +Attach an album to an article/post by placing a gallery metadata tag with the name of the album. gallery:album_name diff --git a/pelicanext/gallery/gallery.py b/pelicanext/gallery/gallery.py index 35c6052..65b5e92 100644 --- a/pelicanext/gallery/gallery.py +++ b/pelicanext/gallery/gallery.py @@ -1,112 +1,6 @@ -""" -Copyright (c) Emmet McPoland - -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() %} -

{{ article.album }}

-
    - {% for image in article.galleryimages %} -
  • - {% endfor %} -
- {% endfor %} - -###gallery.html - - {% for album, images in page.gallery.iteritems() %} -

{{ album }}

-
    - {% for image in images %} -
  • - {% endfor %} -
- {% 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')