Skip to content

Commit 87f3da8

Browse files
committed
Keep Namhoon visible after overflow count in news portraits
1 parent 5899284 commit 87f3da8

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

‎data/news/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ For a paper mentioned without a link (no `paper` URL yet), name it in `paper`:
8181
Faces appear only from these: the authors of the papers (`paper` first, then
8282
linked ones in text order), then people `@tagged` in the text, and only for
8383
current members. Namhoon's portrait is always ordered last; all other members
84-
keep their relative order. This applies before the existing `faces.max` / `+N`
85-
limit and does not change publication author order. Alumni tags show the name
84+
keep their relative order. When the group exceeds `faces.max`, reserve the last visible slot for Namhoon
85+
and place `+N` before him. This does not change publication author order. Alumni tags show the name
8686
without a face. Nothing is guessed from plain names or links. An unknown tag or
8787
paper key stops the build with an error.
8888

‎tests/test_news_faces.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,25 @@ def test_namhoon_last_and_input_unchanged(self):
3030
def test_other_people_keep_order(self):
3131
self.assertIn('aria-label="Beta, Alpha"', str(build.news_faces([self.b, self.a], 3)))
3232

33-
def test_overflow_and_alumni_keep_existing_behavior(self):
33+
def test_overflow_keeps_namhoon_visible_last_and_filters_alumni(self):
3434
old = person("alumnus", "Alumnus", current=False)
3535
result = str(build.news_faces([self.a, self.n, old, self.b, self.c], 3))
3636
self.assertIn('aria-label="Alpha, Beta, Gamma, Namhoon Lee"', result)
3737
self.assertIn('>+2</span>', result)
3838
self.assertNotIn('Alumnus', result)
39-
self.assertNotIn('src="group_profile/namhoonlee.jpg"', result)
39+
self.assertIn('src="group_profile/namhoonlee.jpg"', result)
40+
self.assertLess(result.index('>+2</span>'), result.index('title="Namhoon Lee"'))
41+
self.assertEqual(result.count('class="member-face'), 3)
42+
43+
def test_single_slot_keeps_namhoon_visible(self):
44+
result = str(build.news_faces([self.a, self.n, self.b], 1))
45+
self.assertIn('src="group_profile/namhoonlee.jpg"', result)
46+
self.assertEqual(result.count('class="member-face'), 1)
47+
48+
def test_overflow_without_namhoon_unchanged(self):
49+
result = str(build.news_faces([self.a, self.b, self.c], 2))
50+
self.assertIn('title="Alpha"', result)
51+
self.assertIn('>+2</span>', result)
4052

4153
def test_only_namhoon_or_no_people(self):
4254
self.assertIn('title="Namhoon Lee"', str(build.news_faces([self.n], 3)))

‎tools/build.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,31 @@ def _face_img(person):
192192
def news_faces(people, max_faces):
193193
"""Faces under a news item's date: a few, then "+N" (like Slack)."""
194194
# News portraits always put Namhoon last, without changing author order or
195-
# the relative order of other members. Apply before the existing +N limit.
195+
# the relative order of other members.
196196
people = sorted(
197197
(p for p in people if p["current"]),
198198
key=lambda p: p["tag"] == "namhoonlee",
199199
)
200200
if not people:
201201
return Markup("")
202202
names = ", ".join(p["name"] for p in people)
203-
shown = people[: max_faces - 1] if len(people) > max_faces else people
203+
overflow = len(people) > max_faces
204+
trailing = people[-1] if overflow and people[-1]["tag"] == "namhoonlee" else None
205+
# Reserve the final visible slot for Namhoon, and one slot for +N when
206+
# there is room. The other visible members retain their original order.
207+
shown = people[:max(0, max_faces - 2)] if trailing else (
208+
people[: max_faces - 1] if overflow else people
209+
)
204210
html = Markup('<span class="news-people" aria-label="%s" title="%s">') % (names, names)
205211
for p in shown:
206212
html += Markup('<a class="member-face" title="%s"%s>%s</a>') % (p["name"], _profile_link(p), _face_img(p))
207-
if len(shown) < len(people):
208-
html += Markup('<span class="member-face member-face-more">+%d</span>') % (len(people) - len(shown))
213+
hidden = len(people) - len(shown) - bool(trailing)
214+
if hidden and (not trailing or max_faces > 1):
215+
html += Markup('<span class="member-face member-face-more">+%d</span>') % hidden
216+
if trailing:
217+
html += Markup('<a class="member-face" title="%s"%s>%s</a>') % (
218+
trailing["name"], _profile_link(trailing), _face_img(trailing)
219+
)
209220
return html + Markup("</span>")
210221

211222

0 commit comments

Comments
 (0)