From 9bda955a591037349487bdf38079dcf112e285b1 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 3 May 2011 20:21:16 +0200 Subject: [PATCH] add metadata (author, title, description) from the config file + thumbnail for sub-albums --- sigal/image.py | 2 +- sigal/theme.py | 29 +++++++++++++++++++++++++---- test/sigal.conf | 5 +++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/sigal/image.py b/sigal/image.py index 4eb4b2b..e774d6f 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -77,7 +77,7 @@ class Gallery: # loop on directories for dirpath, dirnames, imglist in self.filelist(): - print "%s / %i images" % (dirpath, len(imglist)) + print ":: %s - %i images" % (dirpath, len(imglist)) img_dir = dirpath.replace(self.input_dir, self.output_dir) diff --git a/sigal/theme.py b/sigal/theme.py index 6611dc5..eddfc69 100644 --- a/sigal/theme.py +++ b/sigal/theme.py @@ -27,6 +27,14 @@ class Theme(): self.theme_dir = os.path.join('themes', theme) self.template = env.get_template(tpl) + self.meta = {} + self.meta['title'] = params.get('album', 'title') \ + if params.has_option('album', 'title') else '' + self.meta['author'] = params.get('album', 'author') \ + if params.has_option('album', 'author') else '' + self.meta['description'] = params.get('album', 'description') \ + if params.has_option('album', 'description') else '' + def filelist(self): "get the list of directories with files of particular extensions" @@ -40,6 +48,15 @@ class Theme(): dirlist = [d for d in dirnames if d not in ignored_dir] yield dirpath, dirlist, imglist + def find_representative(self, path): + """ find the representative image for a given album/path + at the moment, this is the first image found. + """ + + files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) \ + and os.path.splitext(f)[1] in self.fileExtList] + return files[0] + def render(self): copy_tree(os.path.abspath(self.theme_dir), @@ -61,16 +78,20 @@ class Theme(): albums = [] for d in dirnames: - album = {'path': d+"/"+INDEX_PAGE, - 'name': d + alb_thumb = self.find_representative(os.path.join(dirpath, d)) + album = {'path': os.path.join(d, INDEX_PAGE), + 'name': d, + 'thumb': os.path.join(d, self.thumb_dir, + self.thumb_prefix+alb_thumb), } albums.append(album) # print album - page = self.template.render(title=dirpath, images=images, + page = self.template.render(self.meta, + images=images, albums=albums, theme=theme) # save - f = open(dirpath+"/"+INDEX_PAGE,"w") + f = open(os.path.join(dirpath, INDEX_PAGE),"w") f.write(page) f.close() diff --git a/test/sigal.conf b/test/sigal.conf index a8f6022..5ad586b 100644 --- a/test/sigal.conf +++ b/test/sigal.conf @@ -1,3 +1,8 @@ +[album] + +title = My Beautiful Gallery +author = John Doe +description = Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est. [sigal]