From 8a446413dc1f1c6adddc76f5335a91fe1fa0f810 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sun, 9 Aug 2026 15:35:22 +0200 Subject: Inline small gallery layout helpers This removes two one-use helper functions from the gallery plugin and inlines their simple calculations at the call sites. The layout scoring and subset mask creation remain unchanged, but the code is a little shorter and easier to follow. --- packages/gallery/lektor_gallery.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'packages/gallery') diff --git a/packages/gallery/lektor_gallery.py b/packages/gallery/lektor_gallery.py index b2f5e9f..779aa38 100644 --- a/packages/gallery/lektor_gallery.py +++ b/packages/gallery/lektor_gallery.py @@ -238,10 +238,7 @@ def select_cached_layout( return min( candidates, key=lambda candidate: ( - final_score( - candidate, - target_ratio=target_ratio, - ), + abs(log(candidate.ratio / target_ratio)) + structure_score(candidate), candidate.signature, ), ) @@ -398,7 +395,7 @@ def build_candidates( all_indices, subset_size, ): - mask = mask_for(indices) + mask = sum(1 << index for index in indices) first_bit = mask & -mask generated: dict[float, Node] = {} @@ -426,11 +423,6 @@ def build_candidates( return candidates[(1 << count) - 1] -def mask_for(indices) -> int: - """Return the bit mask representing a sequence of image indices.""" - return sum(1 << index for index in indices) - - def combine_partitions( generated: dict[float, Node], first_candidates: Sequence[Node], @@ -599,15 +591,6 @@ def structure_score(node: Node) -> float: ) -def final_score( - node: Node, - *, - target_ratio: float, -) -> float: - """Score a complete layout against the requested gallery ratio.""" - return abs(log(node.ratio / target_ratio)) + structure_score(node) - - class GalleryPlugin(Plugin): name = "Gallery" description = "Static aspect-ratio-aware image gallery layouts." -- cgit v1.3.1