Browse Source

Change "representative" to "thumbnail".

pull/17/merge
Simon 13 years ago
parent
commit
025b868a91
  1. 4
      docs/index.rst
  2. 22
      sigal/gallery.py
  3. 4
      sigal/writer.py
  4. 2
      tests/sample/dir1/index.md
  5. 10
      tests/test_gallery.py

4
docs/index.rst

@ -116,12 +116,12 @@ named ``index.md`` :
::
Title: Another example gallery
Representative: test2.jpg
Thumbnail: test2.jpg
And a *cool* description.
If this file does not exist the directory's name is used for the title, and
the first image of the directory is used as representative.
the first image of the directory is used as thumbnail.
Changelog

22
sigal/gallery.py

@ -74,21 +74,19 @@ class PathsDb(object):
path_noim = [path for path in self.db['paths_list']
if not self.db[path]['img'] and path != '.']
# directories with images: find the representative
# directories with images: find the thumbnail if it is not set
for path in path_im:
alb_thumb = self.db[path].setdefault('representative', '')
alb_thumb = self.db[path].setdefault('thumbnail', '')
if (not alb_thumb) or \
(not os.path.isfile(join(path, alb_thumb))):
alb_thumb = self.find_representative(path)
self.db[path]['representative'] = alb_thumb
self.db[path]['thumbnail'] = self.get_thumbnail(path)
# directories without images. Start with the deepest ones.
for path in reversed(sorted(path_noim, key=lambda x: x.count('/'))):
if self.db[path]['subdir']:
# use the representative of their sub-directories
# use the thumbnail of their sub-directories
subdir = self.db[path]['subdir'][0]
subrepr = self.db[subdir]['representative']
self.db[path]['representative'] = subrepr
self.db[path]['thumbnail'] = self.db[subdir]['thumbnail']
else:
# else remove all info about this directory
self.logger.info("Directory '%s' is empty", path)
@ -98,8 +96,8 @@ class PathsDb(object):
parent = os.path.normpath(join(path, '..'))
self.db[parent]['subdir'].remove(path)
def find_representative(self, path):
"Find the representative image for a given path"
def get_thumbnail(self, path):
"Find the thumbnail image for a given path"
for f in self.db[path]['img']:
# find and return the first landscape image
@ -216,7 +214,7 @@ def get_metadata(path):
""" Get album metadata from DESCRIPTION_FILE:
- title
- representative image
- thumbnail image
- description
"""
@ -228,7 +226,7 @@ def get_metadata(path):
'title': os.path.basename(path).replace('_', ' ')
.replace('-', ' ').capitalize(),
'description': '',
'representative': ''
'thumbnail': ''
}
else:
md = markdown.Markdown(extensions=['meta'])
@ -241,7 +239,7 @@ def get_metadata(path):
meta = {
'title': md.Meta.get('title', [''])[0],
'description': html,
'representative': md.Meta.get('representative', [''])[0]
'thumbnail': md.Meta.get('thumbnail', [''])[0]
}
return meta

4
sigal/writer.py

@ -141,10 +141,10 @@ class Writer(object):
for d in paths[relpath]['subdir']:
dpath = os.path.normpath(os.path.join(relpath, d))
alb_thumb = paths[dpath]['representative']
alb_thumb = paths[dpath]['thumbnail']
thumb_name = get_thumb(self.settings, alb_thumb)
thumb_path = os.path.join(self.output_dir, dpath, thumb_name)
self.logger.debug("Representative path : %s", thumb_path)
self.logger.debug("Thumbnail path : %s", thumb_path)
# generate the thumbnail if it is missing (if
# settings['make_thumbs'] is False)

2
tests/sample/dir1/index.md

@ -1,5 +1,5 @@
Title: An example gallery
Representative: test1.jpg
Thumbnail: test1.jpg
## Hello world !

10
tests/test_gallery.py

@ -41,12 +41,12 @@ class TestPaths(unittest.TestCase):
self.assertItemsEqual(paths['.']['subdir'], ['dir1', 'dir2'])
self.assertItemsEqual(paths['dir1']['img'], ['test1.jpg', 'test2.jpg'])
self.assertEqual(paths['dir1']['representative'], u'test1.jpg')
self.assertEqual(paths['dir1']['thumbnail'], u'test1.jpg')
self.assertEqual(paths['dir1']['title'], u'An example gallery')
def test_find_representative(self):
self.assertEqual(self.paths.find_representative('dir1'), u'test1.jpg')
self.assertEqual(self.paths.find_representative('dir1/test'),
def test_get_thumbnail(self):
self.assertEqual(self.paths.get_thumbnail('dir1'), u'test1.jpg')
self.assertEqual(self.paths.get_thumbnail('dir1/test'),
u'test2.jpg')
@ -56,7 +56,7 @@ class TestMetadata(unittest.TestCase):
def test_get_metadata(self):
m = get_metadata(os.path.join(SAMPLE_DIR, 'dir1'))
self.assertEqual(m['title'], 'An example gallery')
self.assertEqual(m['representative'], 'test1.jpg')
self.assertEqual(m['thumbnail'], 'test1.jpg')
m = get_metadata(os.path.join(SAMPLE_DIR, 'dir1', 'test'))
self.assertEqual(m['title'], 'Test')

Loading…
Cancel
Save