Peach: Local-first video metadata scraper and media manager.
fix(web): 女优页头标签换成中文、多的收进「+N」,换头像加号贴回圆框
longmeidaof4f1d6fd60f8
diff --git a/docs/adr/0069-performer-page-header-shows-five-facts-and-grouped-names.md b/docs/adr/0069-performer-page-header-shows-five-facts-and-grouped-names.mdindex 2240e6263..f876b49b8 100644--- a/docs/adr/0069-performer-page-header-shows-five-facts-and-grouped-names.md+++ b/docs/adr/0069-performer-page-header-shows-five-facts-and-grouped-names.md@@ -19,6 +19,8 @@ ADR-0067 把 minnano-av 资料表落进了 `performer_profile`,当时写明「血型、出身地、趣味、博客都在账本里,但不上页头。页头是用来认人的,这五项回答「她是谁、什么体型、什么时候出道、还拍不拍」;再多几项,资料表会比身份信息高出一截,头像两侧留空。取不到的项服务端不下发,页面也就不画那一格,不写「未取得」。+站上的标签与作品标签走同一张映射(`genre_taxonomy` 加复核页的用户决定),换成 Peach 中文标签,同义的并成一个;+判为非内容的不出,表里未收录的照原文列。那一格只列前四个,余下的收进「+N」浮层。**二、别名按名义分组。** 名字下面那一行是读音加前三个名字,其余收进「+N」浮层,分组如下:现名(资料页主名)、旧名义(没有注记的别名)、各渠道名义(按人数从多到少)、其它(账本里有、页上没列的写法)。diff --git a/frontend/e2e/design.test.ts b/frontend/e2e/design.test.tsindex df2545c01..b321d7c5f 100644--- a/frontend/e2e/design.test.ts+++ b/frontend/e2e/design.test.ts@@ -359,7 +359,7 @@ const PROFILED = {birth_date: '1991-07-21', age: 35, height: 155, bust: 86, waist: 60, hip: 87, cup: 'F',debut_date: '2010-12-02', debut_title: 'セキララ 〜今どき世代のゆるい性事情〜 03 はじめての撮影でとまどう素人娘の記録',active: { from: '2010', to: '2023' },- tags: ['美乳', '美尻', 'レズ', 'アナル', '巨乳', '巨尻', '美人'],+ tags: ['美乳', '美臀', '百合', '肛交', '巨乳', '高颜值', '苗条', '高个', '剛毛'],},name_groups: {reading: 'しのだゆう', shown: ['篠崎ゆう子', '高木早希', '橋本真紀'], total: 7,@@ -1851,6 +1851,74 @@ describe('设计决定', () => {});}+ it('资料表的标签只列前四个,余下的收进「+N」,浮层进顶层列全部标签', { timeout: 60_000 }, async () => {+ const opened = await openProfiledPerformer(browser, DESKTOP);+ try {+ const page = opened.page;+ const cell = await page.locator('.entityfacts dd.facttags').evaluate((dd) => ({+ shown: [...dd.querySelectorAll(':scope > .facttag')].map((tag) => tag.textContent!.trim()),+ more: dd.querySelector(':scope > .factmore')?.textContent?.trim() ?? '',+ }));+ assert.deepEqual(cell.shown, PROFILED.profile.tags.slice(0, 4), '标签那一格不是前四个');+ assert.equal(cell.more, '+5', '「+N」数的不是剩下那几个标签');+ const pop = page.locator('#entityTagPop');+ assert.equal(await pop.isVisible(), false);+ await page.locator('.factmore').hover();+ await pop.waitFor({ state: 'visible', timeout: 5_000 });+ const shown = await pop.evaluate((element) => {+ const box = element.getBoundingClientRect();+ return {+ topLayer: element.matches(':popover-open'),+ inView: box.left >= 0 && box.right <= innerWidth && box.top >= 0 && box.bottom <= innerHeight,+ title: element.querySelector('.aliaspophead')?.textContent?.trim(),+ tags: [...element.querySelectorAll('.facttag')].map((tag) => tag.textContent!.trim()),+ };+ });+ assert.equal(shown.topLayer, true, '标签浮层没进顶层,会被资料卡的 overflow:hidden 裁掉');+ assert.ok(shown.inView, '标签浮层越出了视口');+ assert.equal(shown.title, '9 个标签');+ assert.deepEqual(shown.tags, PROFILED.profile.tags);+ await page.mouse.move(1, 1);+ await pop.waitFor({ state: 'hidden', timeout: 5_000 });+ // 点一下钉住:指针离开也不收,Escape 才收。+ await page.locator('.factmore').click();+ await page.mouse.move(1, 1);+ await page.waitForTimeout(300);+ assert.equal(await pop.isVisible(), true, '点按钉住的标签浮层指针一走就收了');+ await page.keyboard.press('Escape');+ assert.equal(await pop.isVisible(), false, 'Escape 收不起标签浮层');+ assert.deepEqual(opened.problems, []);+ } finally {+ await opened.close();+ }+ });++ it('换头像的加号量在圆框上:整行比圆框高时也贴着圆框右下角', { timeout: 60_000 }, async () => {+ const opened = await openProfiledPerformer(browser, { name: 'wide', width: 1440, height: 900, mobile: false });+ try {+ const page = opened.page;+ const button = page.locator('.entityportraitwrap [data-avatar-picker] button');+ await button.waitFor({ timeout: 15_000 });+ // 行有多高看她有多少资料、别名那一行折不折;这里直接把身份列撑高,量的是加号跟不跟圆框。+ await page.addStyleTag({ content: '.entityidentity{padding-block:40px}' });+ const box = await page.evaluate(() => {+ const rect = (element: Element) => element.getBoundingClientRect();+ const wrap = rect(document.querySelector('.entityportraitwrap')!);+ const circle = rect(document.querySelector('.entityportrait')!);+ const plus = rect(document.querySelector('.entityportraitwrap [data-avatar-picker] button')!);+ return { wrap: wrap.height, circle: { right: circle.right, bottom: circle.bottom, height: circle.height },+ plus: { right: plus.right, bottom: plus.bottom } };+ });+ assert.ok(box.wrap > box.circle.height + 8, `这一行没有比圆框高,用例量不出偏移(行 ${box.wrap},圆框 ${box.circle.height})`);+ // Tailwind 的 `right-1 bottom-1`:按钮离圆框外框右、下各 4px。+ assert.ok(Math.abs(box.circle.bottom - box.plus.bottom - 4) < 1, `加号没有贴着圆框底边:${JSON.stringify(box)}`);+ assert.ok(Math.abs(box.circle.right - box.plus.right - 4) < 1, `加号没有贴着圆框右边:${JSON.stringify(box)}`);+ assert.deepEqual(opened.problems, []);+ } finally {+ await opened.close();+ }+ });+it('女优页头深色主题:资料表与别名浮层跟着主题取墨色和浮层底', { timeout: 60_000 }, async () => {const opened = await openProfiledPerformer(browser, DESKTOP, 'dark');try {diff --git a/src/peach/performer_header.py b/src/peach/performer_header.pyindex 5758b61b8..ebd69f293 100644--- a/src/peach/performer_header.py+++ b/src/peach/performer_header.py@@ -23,6 +23,8 @@ import sqlite3from datetime import datefrom .entities import normalize_entity_name+from .genre_decisions import load_genre_decisions+from .genre_taxonomy import resolve_genrefrom .kanji import fold_glyphsfrom .metadata_alias_resolve import PLANNING_ALIAS_SOURCEfrom .minnano_av import name_entries@@ -55,7 +57,7 @@ def age_on(birth: str, today: date) -> int | None:return today.year - born.year - ((today.month, today.day) < (born.month, born.day))-def facts(row: dict | None, today: date) -> dict:+def facts(row: dict | None, today: date, decisions: dict[str, str | None] | None = None) -> dict:"""页头那五项要的值,只放有的。`row` 是 `read_profile` 交回的一行。"""row = row or {}found: dict = {}@@ -71,12 +73,32 @@ def facts(row: dict | None, today: date) -> dict:until = row.get("active_until")found["active"] = {"from": row["debut_year"],**({"to": until} if until else {"ongoing": True})}- tags = [str(tag) for tag in row.get("tags") or [] if str(tag).strip()]+ tags = site_tags(row.get("tags") or [], decisions)if tags:found["tags"] = tagsreturn found+def site_tags(raw: list, decisions: dict[str, str | None] | None = None) -> list[str]:+ """站上的标签换成 Peach 的中文标签,同义的并成一个(`美人`、`美少女` 都是「高颜值」)。++ 与作品标签走同一张表和同一批用户决定(`genre_taxonomy.resolve_genre`);用户判为不是内容的+ 不出。表里还没收录的照原文列:那是站上确有的说法,丢掉就少了一项读数。+ """+ tags: list[str] = []+ for tag in raw:+ text = " ".join(str(tag).split())+ if not text:+ continue+ mapped = resolve_genre(text, decisions)+ if mapped is None:+ continue+ shown = mapped or text+ if shown not in tags:+ tags.append(shown)+ return tags++def page_names(row: dict | None) -> dict:"""资料页上的名字:{name, reading, aliases};`aliases` 一个写法一项,带着渠道注记。"""if not row:@@ -170,10 +192,10 @@ def name_groups(connection: sqlite3.Connection, entity_id: int, canonical: str,"groups": sorter.groups}-def _has_table(connection: sqlite3.Connection) -> bool:+def _has_table(connection: sqlite3.Connection, table: str = TABLE) -> bool:"""迁移 `0036` 应用之前账本里没有这张表:页头照常出,只是没有资料。"""return connection.execute("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?",- (TABLE,)).fetchone() is not None+ (table,)).fetchone() is not Nonedef profiled(connection: sqlite3.Connection) -> set[int]:@@ -189,5 +211,6 @@ def header(connection: sqlite3.Connection, entity_id: int, canonical: str,today: date | None = None) -> dict:"""`q_entity` 给女优页并进去的两项。"""row = read_profile(connection, entity_id) if _has_table(connection) else None- return {"profile": facts(row, today or date.today()),+ decisions = load_genre_decisions(connection) if row and _has_table(connection, "genre_decision") else None+ return {"profile": facts(row, today or date.today(), decisions),"name_groups": name_groups(connection, entity_id, canonical, page_names(row))}diff --git a/tests/test_performer_header.py b/tests/test_performer_header.pyindex bc45b44ed..38a622ca7 100644--- a/tests/test_performer_header.py+++ b/tests/test_performer_header.py@@ -13,6 +13,7 @@ from pathlib import Pathfrom peach import minnano_av, performer_headerfrom peach import web_contract as rm_webfrom peach.entities import normalize_entity_name+from peach.genre_decisions import record_genre_decisionfrom peach.performer_profiles import write_profilefrom peach.web_entity import q_entity_shapesfrom support.ledger import fresh_ledger@@ -117,7 +118,7 @@ class HeaderTests(Case):"birth_date": "1991-07-21", "age": 35, "height": 155, "bust": 86, "waist": 60,"hip": 87, "cup": "F", "debut_date": "2010-12-02","debut_title": "セキララ 〜今どき世代のゆるい性事情〜 03",- "active": {"from": 2010, "to": 2023}, "tags": ["美乳", "美尻", "レズ"]})+ "active": {"from": 2010, "to": 2023}, "tags": ["美乳", "美臀", "百合"]})groups = head["name_groups"]self.assertEqual(groups["reading"], "しのだゆう")self.assertEqual(groups["shown"], ["篠田ゆう", "篠崎ゆう子", "高木早希"])@@ -146,6 +147,16 @@ class HeaderTests(Case):"reading": "しゃくありす", "shown": ["釈アリス"], "total": 1,"groups": [{"label": "", "names": [{"name": "釈アリス"}]}]})+ def test_site_tags_speak_peach_chinese_and_follow_the_user_decisions(self):+ raw = ["美人", "美少女", "巨尻", "美尻", "剛毛", "カリビアン", " "]+ self.assertEqual(performer_header.site_tags(raw), ["高颜值", "美臀", "剛毛", "カリビアン"])+ with self.connection:+ record_genre_decision(self.connection, "剛毛", "多毛", STAMP)+ record_genre_decision(self.connection, "カリビアン", None, STAMP)+ shinoda = self.entity("篠田优")+ self.land(shinoda, SHINODA.replace(">レズ<", ">剛毛<").replace(">美尻<", ">カリビアン<"))+ self.assertEqual(self.header(shinoda, "篠田优")["profile"]["tags"], ["美乳", "多毛"])+def test_age_turns_on_the_birthday(self):self.assertEqual(performer_header.age_on("1991-07-21", date(2026, 7, 20)), 34)self.assertEqual(performer_header.age_on("1991-07-21", date(2026, 7, 21)), 35)diff --git a/web/app.js b/web/app.jsindex 462fe2e74..21403e438 100644--- a/web/app.js+++ b/web/app.js@@ -4919,9 +4919,23 @@ function entityFactsHtml(p){const active=p.active||{};if(active.from)row('calendar-range','出演期间',esc(`${active.from}${active.ongoing?' – 至今':active.to?` – ${active.to}`:''}`),' class="num"');- if((p.tags||[]).length)row('tags','标签',p.tags.map(tag=>`<span class="facttag">${esc(tag)}</span>`).join(''),' class="facttags"');+ const tags=p.tags||[];+ if(tags.length)row('tags','标签',factTagsHtml(tags),' class="facttags"');return rows.length?`<dl class="entityfacts">${rows.join('')}</dl>`:'';}+/* 标签那一格只列前几个,余下的收进「+N」,浮层里一次看全,和名字那一行的别名同一个做法:+ 标签多的人有十几个,全摊开会把资料表撑成三四行,头像那一栏跟着被拉高。只多出一个时+ 直接列出来:「+1」和那一个标签一样宽。字是服务端换好的 Peach 中文标签。 */+const FACT_TAGS_SHOWN=4;+function factTagsHtml(tags){+ const face=tag=>`<span class="facttag">${esc(tag)}</span>`;+ const cut=tags.length>FACT_TAGS_SHOWN+1?FACT_TAGS_SHOWN:tags.length,rest=tags.length-cut;+ const more=rest?`<button type="button" class="factmore" aria-expanded="false" aria-controls="entityTagPop"+ aria-label="另外 ${rest} 个标签">+${rest}</button><div class="popmenu aliaspop" id="entityTagPop" popover="manual"+ role="group" aria-label="${tags.length} 个标签"><p class="aliaspophead">${tags.length} 个标签</p><div class="facttags">${+ tags.map(face).join('')}</div></div>`:'';+ return tags.slice(0,cut).map(face).join('')+more;+}/* 名字下面那一行的别名:读音在最前,接着是前几个名义,余下的收进「+N」。浮层按名义分组(现名、旧名义、各渠道、其它),同一个人用过的名字在这里一次看全。`r18:performer` 的罗马字和作品起的一次性称呼由服务端排除,这里只排版。 */@@ -4946,9 +4960,13 @@ function performerLinkName(link,agency){/* 「+N」的浮层与订阅新作的说明同一套:`popover` 进顶层,资料卡的 `overflow:hidden` 裁不到它;位置按视口算,默认贴按钮下方 8px,下面放不下翻上去,左右夹在视口内 8px。指针悬停或键盘聚焦就出,指针挪到浮层上读名字时不收;点一下钉住(触屏只有这一条路),- 再点、点别处或 Escape 收起。 */-function wireAliasPop(){- const more=$('#index').querySelector('.aliasmore'),pop=$('#entityAliasPop');+ 再点、点别处或 Escape 收起。别名与标签的两个「+N」各接一份。 */+function wireHeroPops(){+ const index=$('#index');+ wireHeroPop(index.querySelector('.aliasmore'),$('#entityAliasPop'));+ wireHeroPop(index.querySelector('.factmore'),$('#entityTagPop'));+}+function wireHeroPop(more,pop){if(!more||!pop)return;const open=()=>pop.matches(':popover-open');const place=()=>{@@ -8634,7 +8652,7 @@ async function openEntity(kind,name,push=true){wireHorizontalScroller($('#index').querySelector('.entitytagbar .filterscroll'));wireNamePicker(kind,d.canonical_name,d.user_aliases||[]);wireEntityFeed(Number(d.id));- wireAliasPop();+ wireHeroPops();entityPhotos=photos&&!photos.error?photos:null;if(entityMediaView.media==='photos'&&!photosAvailable())entityMediaView=emptyMediaView();renderEntityMediaToggle(kind,name,filters);diff --git a/web/css/07-entity.css b/web/css/07-entity.cssindex 8dca67e8a..48b27fc30 100644--- a/web/css/07-entity.css+++ b/web/css/07-entity.css@@ -32,6 +32,13 @@/* 圆框外面这一层只为换头像那枚加号存在:圆框自己是 `overflow:hidden`(图要被裁成圆的),贴在它边上的按钮放进去就没了。 */.entityportraitwrap{position:relative;width:max-content;max-width:100%}+/* 外面这一层拉满整行的高,圆框却封顶 160px、竖直居中:资料表的标签折成几行时,行比圆框高,+ 加号贴这一层的角就掉到圆框下面去了。所以挂加号的宿主叠成和圆框一样大、一样位置的一块,+ 高度与居中取圆框同一个 `clamp`,加号的 `right/bottom` 就量在圆框上。它盖在脸上,不接指针。+ 不用 `transform` 居中:它会给弹层的 `fixed` 遮罩另起包含块。 */+.entityportraitwrap>[data-avatar-picker]{position:absolute;left:0;right:0;height:clamp(120px,100%,160px);+ top:calc((100% - clamp(120px,100%,160px)) / 2);pointer-events:none}+.entityportraitwrap>[data-avatar-picker]>*{pointer-events:auto}/* `position:relative` 是给人脸放大留的包含块:放大后的 img 转成绝对定位,偏移必须相对这个圆框算,否则会挂到最近的定位祖先上去。见 app.js 的 avatarFrame。 */.entityportrait{height:100%;min-height:120px;max-height:160px;width:auto;@@ -77,12 +84,16 @@.metaitem{display:inline-flex;align-items:center;gap:6px;min-width:0}.aliasline{flex-wrap:wrap}.aliasnames>span+span::before,.aliaspop dd>span+span::before{content:"·";margin:0 6px;color:var(--muted)}-.aliasmore{height:22px;margin-left:4px;padding:0 8px;border:1px solid var(--line);border-radius:var(--pill-radius);+.aliasmore,.factmore{height:22px;margin-left:4px;padding:0 8px;border:1px solid var(--line);border-radius:var(--pill-radius);background:transparent;color:var(--ink);font:inherit;font-size:var(--fs-xs);cursor:pointer}-.aliasmore:hover,.aliasmore[aria-expanded="true"]{background:color-mix(in srgb,var(--ink) 8%,var(--ground))}+.aliasmore:hover,.aliasmore[aria-expanded="true"],.factmore:hover,.factmore[aria-expanded="true"]{+ background:color-mix(in srgb,var(--ink) 8%,var(--ground))}+/* 标签那一格的「+N」排在标签的流里,间距归 flex 的 gap。 */+.factmore{margin-left:0}/* 「+N」的浮层借锚定菜单那身盒子(`.popmenu`:底色、描边、圆角、投影与开合动效),它是`popover`,进顶层才不被资料卡的 `overflow:hidden` 裁掉;`.popmenu` 的 `display:grid` 会压过- 浏览器给没打开的 popover 的 `display:none`,所以这里自己收起。位置由 `wireAliasPop` 算。 */+ 浏览器给没打开的 popover 的 `display:none`,所以这里自己收起。位置由 `wireHeroPop` 算。+ 标签的「+N」浮层(`#entityTagPop`)是同一身盒子,里面的标签仍是 `.facttags` 那一排。 */.popmenu.aliaspop{width:max-content;max-width:min(440px,calc(100vw - 16px));padding:12px 14px;gap:8px;color:var(--ink);font-size:var(--fs-sm);line-height:1.5;text-align:left}.popmenu.aliaspop:not(:popover-open){display:none}