"""Give each work a tile size derived from what it actually contains. A uniform grid gives a ten-hour festival set and a two-line workshop note the same visual weight, which is both untrue and the most dated thing about the original layout. Weight is taken from evidence already in the entry: how much imagery survived, whether there is video, and how much was written about it. """ import re from pelican import signals IMG = re.compile(r']+>', ' ', body).split()) score = imgs + vids * 4 + words / 90.0 # a work with no surviving image cannot carry a large tile: it would be a # big rectangle of static, which reads as a fault rather than a choice if content.metadata.get('thumb_missing') or not content.metadata.get('thumb'): size = 'sm' elif score >= 9: size = 'lg' elif score >= 4.5: size = 'md' else: size = 'sm' content.metadata['tilesize'] = size content.metadata['tilescore'] = round(score, 1) def register(): signals.content_object_init.connect(_weigh)