Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Alsina committed Jun 12, 2017
2 parents 0eb37c0 + fe852da commit a7f1fb6
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 19 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Expand Up @@ -48,6 +48,7 @@
* `Grzegorz Śliwiński <https://github.com/fizyk>`_
* `Guillermo O. Freschi <https://github.com/Tordek>`_
* `h4ckninja <https://github.com/h4ckninja>`_
* `Guilhem Bonnefille <https://github.com/guyou>`_
* `Hardening <https://github.com/hardening>`_
* `Hong Xu <https://www.topbug.net>`_
* `Ivan Teoh <https://github.com/ivanteoh>`_
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,12 @@
New in master
=============

Features
--------

* Add support for extended metadata in galleries


New in v7.8.8
=============

Expand Down
5 changes: 5 additions & 0 deletions docs/manual.txt
Expand Up @@ -1878,6 +1878,11 @@ If ``USE_FILENAME_AS_TITLE`` is True the filename (parsed as a readable string)
is used as the photo caption. If the filename starts with a number, it will
be stripped. For example ``03_an_amazing_sunrise.jpg`` will be render as *An amazing sunrise*.

If you add a ``.meta`` to an image, the metadata (title, description, author,
copyright...) will be used.
For example, ``03_an_amazing_sunrise.meta`` will be used for extended metadata to
``03_an_amazing_sunrise.jpg``.

Here is a `demo gallery </galleries/demo>`_ of historic, public domain Nikola
Tesla pictures taken from `this site <http://kerryr.net/pioneers/gallery/tesla.htm>`_.

Expand Down
1 change: 1 addition & 0 deletions docs/theming.txt
Expand Up @@ -236,6 +236,7 @@ These are the templates that come with the included themes:
+ ``url_thumb``: URL for the thumbnail.
+ ``title``: The title of the image.
+ ``size``: A dict containing ``w`` and ``h``, the real size of the thumbnail.
+ any other fields possibly added in the associated ``.meta`` file (optional).

* ``photo_array_json``: a JSON dump of photo_array, used in the bootstrap theme by flowr.js

Expand Down
@@ -0,0 +1,2 @@
.. title: Man-made lightning 1
.. description: Man-made lightning in Tesla's lab (this photo is believed to be a double exposure to produce a more dramatic effect)
2 changes: 2 additions & 0 deletions nikola/data/themes/base/assets/css/theme.css
Expand Up @@ -271,6 +271,8 @@ img {
.thumbnails > li {
display: inline-block;
margin-right: 10px;
width: 200px;
vertical-align: top;
}

.thumbnails > li:last-of-type {
Expand Down
7 changes: 7 additions & 0 deletions nikola/data/themes/base/templates/gallery.tmpl
Expand Up @@ -30,6 +30,13 @@
%for image in photo_array:
<li><a href="${image['url']}" class="thumbnail image-reference" title="${image['title']|h}">
<img src="${image['url_thumb']}" alt="${image['title']|h}" /></a>
%if 'description' in image:
<p>${image['description']}</p>
%endif
%if 'author' in image:
<p>Author: ${image['author']}</p>
%endif
</li>
%endfor
</ul>
</noscript>
Expand Down
52 changes: 34 additions & 18 deletions nikola/plugins/task/galleries.py
Expand Up @@ -51,6 +51,7 @@
from nikola import utils
from nikola.image_processing import ImageProcessor
from nikola.post import Post
from nikola.post import get_metadata_from_meta_file

_image_size_cache = {}

Expand Down Expand Up @@ -232,13 +233,24 @@ def gen_tasks(self):

image_name_list = [os.path.basename(p) for p in image_list]

img_metadata = []
# FIXME for readability, invert if and for-loop
if self.kw['use_filename_as_title']:
img_titles = []
for fn in image_name_list:
name_without_ext = os.path.splitext(os.path.basename(fn))[0]
img_titles.append(utils.unslugify(name_without_ext, lang))
metadata = dict()
metadata['title'] = utils.unslugify(name_without_ext, lang)
img_metadata.append(metadata)
else:
img_titles = [''] * len(image_name_list)
for fn in image_name_list:
metadata = dict()
metadata['title'] = ''
img_metadata.append(metadata)

for idx, fn in enumerate(image_name_list):
metadata, newstyle = get_metadata_from_meta_file(os.path.join(gallery,fn))
if metadata != None:
img_metadata[idx].update(metadata)

thumbs = ['.thumbnail'.join(os.path.splitext(p)) for p in image_list]
thumbs = [os.path.join(self.kw['output_folder'], output_folder, os.path.relpath(t, input_folder)) for t in thumbs]
Expand Down Expand Up @@ -300,7 +312,7 @@ def gen_tasks(self):
dst,
context.copy(),
dest_img_list,
img_titles,
img_metadata,
thumbs,
file_dep))],
'clean': True,
Expand All @@ -327,7 +339,7 @@ def gen_tasks(self):
(self.gallery_rss, (
image_list,
dst_img_list,
img_titles,
img_metadata,
lang,
self.site.link("gallery_rss", gallery, lang),
rss_dst,
Expand Down Expand Up @@ -545,7 +557,7 @@ def render_gallery_index(
output_name,
context,
img_list,
img_titles,
img_metadata,
thumbs,
file_dep):
"""Build the gallery index."""
Expand All @@ -557,20 +569,20 @@ def url_from_path(p):
url = '/'.join(os.path.relpath(p, os.path.dirname(output_name) + os.sep).split(os.sep))
return url

all_data = list(zip(img_list, thumbs, img_titles))
all_data = list(zip(img_list, thumbs, img_metadata))

if self.kw['sort_by_date']:
all_data.sort(key=lambda a: self.image_date(a[0]))
else: # Sort by name
all_data.sort(key=lambda a: a[0])

if all_data:
img_list, thumbs, img_titles = zip(*all_data)
img_list, thumbs, img_metadata = zip(*all_data)
else:
img_list, thumbs, img_titles = [], [], []
img_list, thumbs, img_metadata = [], [], []

photo_array = []
for img, thumb, title in zip(img_list, thumbs, img_titles):
for img, thumb, metadata in zip(img_list, thumbs, img_metadata):
w, h = _image_size_cache.get(thumb, (None, None))
if w is None:
if os.path.splitext(thumb)[1] in ['.svg', '.svgz']:
Expand All @@ -580,20 +592,20 @@ def url_from_path(p):
w, h = im.size
_image_size_cache[thumb] = w, h
# Thumbs are files in output, we need URLs
photo_array.append({
metadata.update({
'url': url_from_path(img),
'url_thumb': url_from_path(thumb),
'title': title,
'size': {
'w': w,
'h': h
},
})
photo_array.append(metadata)
context['photo_array'] = photo_array
context['photo_array_json'] = json.dumps(photo_array, sort_keys=True)
self.site.render_template(template_name, output_name, context)

def gallery_rss(self, img_list, dest_img_list, img_titles, lang, permalink, output_path, title):
def gallery_rss(self, img_list, dest_img_list, img_metadata, lang, permalink, output_path, title):
"""Create a RSS showing the latest images in the gallery.
This doesn't use generic_rss_renderer because it
Expand All @@ -602,25 +614,25 @@ def gallery_rss(self, img_list, dest_img_list, img_titles, lang, permalink, outp
def make_url(url):
return urljoin(self.site.config['BASE_URL'], url.lstrip('/'))

all_data = list(zip(img_list, dest_img_list, img_titles))
all_data = list(zip(img_list, dest_img_list, img_metadata))

if self.kw['sort_by_date']:
all_data.sort(key=lambda a: self.image_date(a[0]))
else: # Sort by name
all_data.sort(key=lambda a: a[0])

if all_data:
img_list, dest_img_list, img_titles = zip(*all_data)
img_list, dest_img_list, img_metadata = zip(*all_data)
else:
img_list, dest_img_list, img_titles = [], [], []
img_list, dest_img_list, img_metadata = [], [], []

items = []
for img, srcimg, title in list(zip(dest_img_list, img_list, img_titles))[:self.kw["feed_length"]]:
for img, srcimg, metadata in list(zip(dest_img_list, img_list, img_metadata))[:self.kw["feed_length"]]:
img_size = os.stat(
os.path.join(
self.site.config['OUTPUT_FOLDER'], img)).st_size
args = {
'title': title,
'title': metadata['title'],
'link': make_url(img),
'guid': rss.Guid(img, False),
'pubDate': self.image_date(srcimg),
Expand All @@ -630,10 +642,14 @@ def make_url(url):
mimetypes.guess_type(img)[0]
),
}
if 'description' in metadata:
# Pass the standard description field
args['description'] = metadata['description']
items.append(rss.RSSItem(**args))
rss_obj = rss.RSS2(
title=title,
link=make_url(permalink),
# TODO metadata.description
description='',
lastBuildDate=datetime.datetime.utcnow(),
items=items,
Expand Down
2 changes: 1 addition & 1 deletion nikola/post.py
Expand Up @@ -1082,7 +1082,7 @@ def get_metadata_from_meta_file(path, config=None, lang=None):
if newstylemeta:
# New-style metadata is basically the same as reading metadata from
# a 1-file post.
return get_metadata_from_file(path, config, lang), newstylemeta
return get_metadata_from_file(meta_path, config, lang), newstylemeta
else:
if not _UPGRADE_METADATA_ADVERTISED:
LOGGER.warn("Some posts on your site have old-style metadata. You should upgrade them to the new format, with support for extra fields.")
Expand Down

0 comments on commit a7f1fb6

Please sign in to comment.