Nikola Gallery Setup
Nikola has a very nice built in gallery feature that includes a JS based viewer. There are a number of changes that are needed to make Nikola's handeling of both images and galleries more useful for a site with more of a focus on photography.
EXIF Data
By default, Nikola strips all EXIF data from images. While this is nice from a privacy standpoint, a certain amount of EXIF data is important for a photographer. So, set the following in conf.privacy
PRESERVE_EXIF_DATA = True EXIF_WHITELIST = { "0th": ["Orientation", "XResolution", "YResolution"], "Exif": ["ExposureTime", "FocalLength", "ISOSpeedRatings", "DateTimeOriginal", "Flash", "ShutterSpeedValue"], }
Unfortunately, it would appear that the Python implementation of reading EXIF data is woefully incomplete. It does not appear to be possile to copy information such as Camera Manufacturer, or Lense information. Perhaps in the future I will work on a way of using exiftool
.
Also, at least for the moment, it would appear that changes to the EXIF_WHITELIST
variable do not cause the EXIF data of images in the galleries
folder to be rebuilt, only the images
folder. You will need to do an entire site rebuild to update images in photo galleries. See https://github.com/getnikola/nikola/issues/3357
Gallery Image Order
It would appear that, by default, image order in galleries is done based on file creation time, not embedded EXIF data for capture time. The best way to deal with this is to set GALLERY_SORT_BY_DATE = False
in conf.py
and rename your files, upon export from your photo program, to YYYYMMDD-HHMMSS based on the actual capture date/time. Essentially all photo management programs will allow for this, though details obviously vary by program.
Gallery Metadata
Image titles can come from one of 2 places. The first is from the name of the image. As my images are generally just named by date, that does not work for me. The second option is to create a metadata file metadata.yml
in the gallery folder and create an entry for each individual photo. That is easy to do by hand if you have small galleries, however when you have a gallery with 40+ photos, it gets a little hard to do without making mistakes. Accordingly, I have written a script to generate metadata.yml files in every gallery that has photos. Do note that this may cause rebuilds every time it is run as I overwrite the metadata file with every run.
#!/usr/bin/python import sys, os, yaml from pathlib import Path def process_directory(path_to_process): metadata_path = path_to_process / 'metadata.yml' filelist=sorted(path_to_process.glob("*.jpg")) metadata_document = {} filenames = [] output = [] if filelist != []: for k in filelist: filenames.append(k.name) if metadata_path.exists(): f = open(str(metadata_path), 'r',encoding = 'utf-8') metadata_document=list(yaml.safe_load_all(f)) f.close() for d in metadata_document: #print('Name:',d['name'],'Caption:',d['caption']) if d['name'] in filenames: #print(d['name'],'IS in current files, keeping') output.append(d) filenames.remove(d['name']) #else: #print(d['name'],'not in current files, discarding') for name in filenames: output.append({'name': name, 'caption': name}) if output != []: output = sorted(output, key = lambda i: i['name']) f = open(str(metadata_path), 'w+',encoding = 'utf-8') for d in output: f.write('---\n') f.write('name: ' + d['name'] +'\n') f.write('caption: ' + d['caption']+ '\n') f.close() def directory_walk(path_variable): print('Processing',path_variable) process_directory(path_variable) for subitem in path_variable.iterdir(): if subitem.is_dir(): directory_walk(subitem) os.chdir(sys.path[0]) base_directory = Path('..').resolve() gallery_base_directory = base_directory / 'galleries' directory_walk(gallery_base_directory)
I will likely have further updates in the future and will either update this post or create further posts.
Comments
Comments powered by Disqus