|
@@ -1,6 +1,7 @@
|
|
|
from collections import namedtuple
|
|
|
from json import loads as from_json
|
|
|
from pathlib import Path
|
|
|
+from unicodedata import normalize
|
|
|
|
|
|
'''
|
|
|
This plugin helps loading images for each section.
|
|
@@ -32,7 +33,7 @@ Along with the image files which should be called
|
|
|
IMAGE_PATH = 'image' # relative to the static path
|
|
|
STATIC = ''
|
|
|
|
|
|
-Image = namedtuple('Image', ['name', 'year', 'category', 'description', 'filenames'])
|
|
|
+Image = namedtuple('Image', ['key', 'name', 'year', 'category', 'description', 'main', 'filenames'])
|
|
|
|
|
|
# Functions
|
|
|
|
|
@@ -45,13 +46,17 @@ def images(section):
|
|
|
if metafile.exists():
|
|
|
img_base = path.relative_to(STATIC)
|
|
|
metadata = from_json(metafile.read_text())
|
|
|
+ key = path.name.split()[0]
|
|
|
+ key = int(key) if key.isnumeric() else 0
|
|
|
img = Image(
|
|
|
+ # key should always be the first field to sort images
|
|
|
+ key,
|
|
|
metadata.get('name'),
|
|
|
metadata.get('year'),
|
|
|
metadata.get('category'),
|
|
|
metadata.get('description'),
|
|
|
- [img_base.joinpath(img_name) for img_name in metadata.get('images', [])])
|
|
|
- print(img)
|
|
|
+ img_base.joinpath(normalize('NFC', metadata.get('main'))) if 'main' in metadata else None,
|
|
|
+ [img_base.joinpath(normalize('NFC', img_name)) for img_name in metadata.get('images', [])])
|
|
|
yield img
|
|
|
|
|
|
|
|
@@ -59,3 +64,4 @@ def init_plugin(env, config):
|
|
|
global STATIC
|
|
|
STATIC = config['STATIC']
|
|
|
env.globals['images'] = images
|
|
|
+ env.globals['sorted'] = sorted
|