summaryrefslogtreecommitdiff
path: root/packages/gallery/lektor_gallery.py
diff options
context:
space:
mode:
authorDennis Fink2026-08-09 15:35:22 +0200
committerDennis Fink2026-08-09 15:35:22 +0200
commit8a446413dc1f1c6adddc76f5335a91fe1fa0f810 (patch)
treeaa7d3bf2baef8f748b3779c71978d56fc5b227d6 /packages/gallery/lektor_gallery.py
parent9b7e535fa76efdd4f76c23f3d7dee8d860b60642 (diff)
downloaddennisfink.me-8a446413dc1f1c6adddc76f5335a91fe1fa0f810.tar.gz
dennisfink.me-8a446413dc1f1c6adddc76f5335a91fe1fa0f810.zip
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.
Diffstat (limited to '')
-rw-r--r--packages/gallery/lektor_gallery.py21
1 files changed, 2 insertions, 19 deletions
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."