Repository: getnikola/nikola

Issue:
Add support for default previewimage
The previewimage meta tag is used for Open Graph metadata, among other things. However, not all pages and blog posts will have their own image. It would be cool to be able to provide a generic **default image via the config**, without having to add it manually to all pages that don't feature one already.

(New pages and posts can be generated with the matching previewimage line, of course, but retrofitting all old files is a pain.)


Discussion:
I concur with this need and I add that it would be desirable to have a default previewimage _per section_, if the site has sections. For instance a section can be a periodic column by some author and a photo of the author could be the default preview image.
PRs for either or both the features are welcome. This could be generalized to per-category/site-wide default post metadata.

Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -448,6 +448,8 @@ def __init__(self, **config):
             'FRONT_INDEX_HEADER': '',
             'GALLERY_FOLDERS': {'galleries': 'galleries'},
             'GALLERY_SORT_BY_DATE': True,
+            'GALLERIES_USE_THUMBNAIL': False,
+            'GALLERIES_DEFAULT_THUMBNAIL': None,
             'GLOBAL_CONTEXT_FILLER': [],
             'GZIP_COMMAND': None,
             'GZIP_FILES': False,
diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py
--- a/nikola/plugins/task/galleries.py
+++ b/nikola/plugins/task/galleries.py
@@ -86,6 +86,8 @@ def set_site(self, site):
             'preserve_icc_profiles': site.config['PRESERVE_ICC_PROFILES'],
             'index_path': site.config['INDEX_PATH'],
             'disable_indexes': site.config['DISABLE_INDEXES'],
+            'galleries_use_thumbnail': site.config['GALLERIES_USE_THUMBNAIL'],
+            'galleries_default_thumbnail': site.config['GALLERIES_DEFAULT_THUMBNAIL'],
         }
 
         # Verify that no folder in GALLERY_FOLDERS appears twice
@@ -264,6 +266,7 @@ def gen_tasks(self):
                 folders = []
 
                 # Generate friendly gallery names
+                fpost_list = []
                 for path, folder in folder_list:
                     fpost = self.parse_index(path, input_folder, output_folder)
                     if fpost:
@@ -272,7 +275,15 @@ def gen_tasks(self):
                         ft = folder
                     if not folder.endswith('/'):
                         folder += '/'
-                    folders.append((folder, ft))
+
+                    # TODO: This is to keep compatibility with user's custom gallery.tmpl
+                    # To be removed in v9 someday
+                    if self.kw['galleries_use_thumbnail']:
+                        folders.append((folder, ft, fpost))
+                        if fpost:
+                            fpost_list.append(fpost.source_path)
+                    else:
+                        folders.append((folder, ft))
 
                 context["gallery_path"] = gallery
                 context["folders"] = natsort.natsorted(
@@ -282,6 +293,7 @@ def gen_tasks(self):
                 context["enable_comments"] = self.kw['comments_in_galleries']
                 context["thumbnail_size"] = self.kw["thumbnail_size"]
                 context["pagekind"] = ["gallery_front"]
+                context["galleries_use_thumbnail"] = self.kw['galleries_use_thumbnail']
 
                 if post:
                     yield {
@@ -308,7 +320,7 @@ def gen_tasks(self):
                 yield utils.apply_filters({
                     'basename': self.name,
                     'name': dst,
-                    'file_dep': file_dep + dest_img_list,
+                    'file_dep': file_dep + dest_img_list + fpost_list,
                     'targets': [dst],
                     'actions': [
                         (self.render_gallery_index, (


Test patch: