Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(web): 作品骨架的封面比例跟大图/小图版式走

longmeidao51d402877739
diff --git a/frontend/e2e/design.test.ts b/frontend/e2e/design.test.ts
index 650d3d034..75ab5e863 100644
--- a/frontend/e2e/design.test.ts
+++ b/frontend/e2e/design.test.ts
@@ -1264,6 +1264,26 @@ describe('设计决定', () => {
}
});
+ /* 骨架是列表回来之前那一屏的形状预告:JAV 默认大图,卡片是 3:4 的正封,骨架照 16:9
+ 铺的话,内容一到整屏卡片都被拉高一截。把列表请求扣住,只看骨架本身。 */
+ it('作品骨架的封面比例跟当前版式走:JAV 大图 3:4,首页小图 16:9', { timeout: 60_000 }, async () => {
+ const opened = await visit(browser, '/', DESKTOP);
+ const { page } = opened;
+ await page.route(/\/api\/items\?/, () => {});
+ const skeletonRatio = async (path: string) => {
+ await page.goto(new URL(path, page.url()).href, { waitUntil: 'load' });
+ const cover = page.locator('#grid .catalog-skeleton .skeletoncard i').first();
+ await cover.waitFor({ state: 'attached', timeout: 15_000 });
+ return cover.evaluate((element) => element.getBoundingClientRect().width / element.getBoundingClientRect().height);
+ };
+ try {
+ assert.ok(Math.abs(await skeletonRatio('/?jav=1') - 0.75) < 0.05, 'JAV 大图下骨架封面不是正封比例');
+ assert.ok(Math.abs(await skeletonRatio('/') - 16 / 9) < 0.05, '首页小图下骨架封面不是 16:9');
+ } finally {
+ await opened.close();
+ }
+ });
+
it('卡片悬停反馈不在封面像素上描边', { timeout: 60_000 }, async () => {
const opened = await openCatalog(browser);
try {
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index cb59cc7c9..adab1667b 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -7192,7 +7192,7 @@ class WebUiSourceTests(unittest.TestCase):
"scrollTo({top:0,behavior:matchMedia('(prefers-reduced-motion: reduce)').matches?'auto':'smooth'});")
self.assertIn("html.refiltering{overflow-anchor:none}", stylesheet_source())
# 目录那边的骨架由 loadCatalog() 铺;资料页的集合自己铺一份同样的。
- self.assertCode(" if(host){releaseEntityGrid();host.innerHTML=entityGridSkeletonHtml();fitSkeleton(section)}")
+ self.assertCode(" if(host){releaseEntityGrid();host.innerHTML=catalogSkeletonHtml();fitSkeleton(section)}")
def test_adding_a_filter_only_changes_the_list_underneath(self):
"""点一条筛选,动的只有底下那份名单;上面那几排原地改按下态。
@@ -7705,7 +7705,7 @@ class WebUiSourceTests(unittest.TestCase):
body = body.split("\n}", 1)[0]
self.assertIn("$('#loadSentinel').hidden=true;", body)
self.assertLess(body.index("$('#loadSentinel').hidden=true;"),
- body.index("setGridCards(pageSkeletonHtml"),
+ body.index("setGridCards(catalogSkeletonHtml"),
"哨兵要在骨架铺上之前收掉,别让 dots 和骨架同时存在一帧")
# 目录这条链上收哨兵只有这一处:分支里再补一次就是又一个会漏掉的地方。
ads = self.app_js.split("async function loadJunk(", 1)[1].split("renderJunkNavigation(adsBatch)", 1)[0]
@@ -7715,8 +7715,7 @@ class WebUiSourceTests(unittest.TestCase):
def test_page_loading_uses_one_structural_skeleton_phase(self):
self.assertPageContains("function renderCatalogLoading(label='正在读取作品')")
- self.assertPageContains("setGridCards(pageSkeletonHtml(label,\n"
- " {cards:true,className:'catalog-skeleton postercard-skeleton'}));")
+ self.assertPageContains("setGridCards(catalogSkeletonHtml(label));")
self.assertPageContains("count.setAttribute('aria-label',label);")
self.assertPageContains(".grid>.skeletonpanel{grid-column:1/-1;width:100%;min-width:0}")
self.assertPageContains("function renderInitialSurfaceLoading()")
@@ -7781,10 +7780,10 @@ class WebUiSourceTests(unittest.TestCase):
"'/follow-manage':()=>`<div class=\"follow\">${pageSkeletonHtml('正在读取关注管理',")
self.assertPageContains("{cards:true,count:3,fill:false,className:'followmanage-skeleton'})}</div>`,")
self.assertPageContains(
- "const pageSkeletonHtml=(label,{cards=false,className='',variant='',count,fill}={})=>")
+ "const pageSkeletonHtml=(label,{cards=false,className='',variant='',count,fill,cardRatio}={})=>")
self.assertPageContains("skeletonHtml(label,{variant:variant||(cards?'cards':'panel'),className,")
self.assertPageContains(
- "export function skeletonHtml(label='正在读取内容',{className='',variant='panel',count=6,fill=true,gridClass='',gridSize=''}={})")
+ "export function skeletonHtml(label='正在读取内容',{className='',variant='panel',count=6,fill=true,gridClass='',gridSize='',cardRatio=0}={})")
self.assertPageContains("?Array.from({length:Math.max(1,count)},")
# 版式:一列对上 .followmanage,宽度也跟它一样是 812px 居中。
self.assertPageContains(
diff --git a/web/app.js b/web/app.js
index c2f9a82bf..7070f71b3 100644
--- a/web/app.js
+++ b/web/app.js
@@ -195,11 +195,11 @@ const ROUTES=[
const registerRoute=spec=>{ROUTES.push(spec);return spec};
window.peachRegisterRoute=registerRoute;
-const pageSkeletonHtml=(label,{cards=false,className='',variant='',count,fill}={})=>
+const pageSkeletonHtml=(label,{cards=false,className='',variant='',count,fill,cardRatio}={})=>
skeletonHtml(label,{variant:variant||(cards?'cards':'panel'),className,
gridClass:className.includes('follow-content-skeleton')&&new URLSearchParams(location.search).get('media')==='images'?'followlist followphotowall':'',
gridSize:className.includes('follow-content-skeleton')?photoSize():'',
- ...(count?{count}:{}),...(fill===undefined?{}:{fill})});
+ ...(count?{count}:{}),...(fill===undefined?{}:{fill}),...(cardRatio?{cardRatio}:{})});
/* 关注页的骨架跟首页共用海报卡那套几何:网格算式、卡内每一格都一样,只有归属行
高一点(`.followitem .meta .s` 有 min-height)。上面是它自己的创作者行、题材行和那块
两排的玻璃浮层,形状取 `.tier`、`.tagbar`、`.count` 本身,所以和首页顶栏那两排是
@@ -292,8 +292,7 @@ function renderCatalogLoading(label='正在读取作品'){
fitSkeleton(count);
/* 网格已经挂着时骨架归它自己铺:`#grid` 是它的容器,壳往里写会把 React 根冲掉。 */
if(islandMounted($('#grid')))return;
- setGridCards(pageSkeletonHtml(label,
- {cards:true,className:'catalog-skeleton postercard-skeleton'}));
+ setGridCards(catalogSkeletonHtml(label));
fitSkeleton($('#grid'));
}
/* 每个管理表面的加载态只有一份定义,深链启动和路由到位后都从这里取。
@@ -6589,7 +6588,6 @@ let entityGridRevision=0;
function releaseEntityGrid(){
$('#index').querySelectorAll('[data-entity-grid]').forEach(host=>{releaseHoverPreviews(host);unmountIsland(host)});
}
-const entityGridSkeletonHtml=()=>pageSkeletonHtml('正在读取作品',{cards:true,className:'catalog-skeleton postercard-skeleton'});
function syncEntityFilterFrame(){
const root=$('#index'),top=root.querySelector('.entitytagbar');
const bottom=root.querySelector('.entitysection>.entitycollectionhead');
@@ -6648,7 +6646,7 @@ function markEntityCollectionBusy(kind,name,filters){
/* 名单已经不是刚才那一份了。把旧卡片留在屏幕上等新的回来,等的这一下人读到的是一份
跟头上的筛选对不上的列表——数字在转圈,底下那几十张却还是上一次的答案。 */
const host=section.querySelector('[data-entity-grid]');
- if(host){releaseEntityGrid();host.innerHTML=entityGridSkeletonHtml();fitSkeleton(section)}
+ if(host){releaseEntityGrid();host.innerHTML=catalogSkeletonHtml();fitSkeleton(section)}
}
/* 名册:事务所页是艺人,片商页是旗下 label。和对应的索引页摆的是同一格、同一套版式
设置,只是这批随资料页一起下来了,不再单独请求;读数写的是这一格有多少视频。 */
@@ -6672,7 +6670,7 @@ function renderEntityCollection(kind,name,items,filters){
releaseEntityGrid();
/* 宿主里先铺一份骨架:React 产物头一次装载要等一个来回,这期间不留一块空白。 */
section.innerHTML=`${collectionHeaderHtml({controls:entityCollectionSortsHtml(filters)})}
- <div data-entity-grid>${entityGridSkeletonHtml()}</div>`;
+ <div data-entity-grid>${catalogSkeletonHtml()}</div>`;
section.dataset.total=String(items.total||0);
section.querySelector('h3').textContent=`视频 · ${(items.total||0).toLocaleString()}${entityTags.length?' · '+entityTags.join(' · '):''}`;
wireEntityCollectionHead(section,kind,name,filters);
@@ -6682,7 +6680,7 @@ function renderEntityCollection(kind,name,items,filters){
fetchPage:(offset,signal)=>fetchEntityItems(kind,name,filters,offset,signal),
helpers:gridHelpers,actions:gridActions,layout:catalogGridLayout(),
selectMode,selected:new Set(selected),seekSeconds:appSettings.seekSeconds,
- cache,wireDrag,skeletonHtml:entityGridSkeletonHtml,groupCollapse:appSettings.groupCollapse,
+ cache,wireDrag,skeletonHtml:()=>catalogSkeletonHtml(),groupCollapse:appSettings.groupCollapse,
canLoadMore:()=>!$('#index').hidden&&$('#stats').hidden,
},{isCurrent:()=>section.contains(host)}).catch(error=>console.error(error));
syncEntityFilterFrame();
@@ -7309,7 +7307,7 @@ function showEntityLoading(kind,name){
const head=collectionHeaderHtml({readout:'&nbsp;',loading:true,filterRow:'bottom'});
const body=kind==='agency'
?indexSkeletonHtml({kind:'performers',layout:peopleIndexLayout()})
- :pageSkeletonHtml('正在读取作品',{cards:true,className:'catalog-skeleton postercard-skeleton'});
+ :catalogSkeletonHtml();
const placeholder=entitySkeletonHtml(kind,head,body);
if($('#index').firstElementChild?.dataset.skeleton!==`entity/${kind}`){
$('#index').innerHTML=placeholder;
@@ -8270,6 +8268,18 @@ function catalogGridLayout(){
if(!catalogLayoutValue||Object.keys(next).some(key=>next[key]!==catalogLayoutValue[key]))catalogLayoutValue=next;
return catalogLayoutValue;
}
+/* 作品网格的骨架(目录、回收站、资料页作品区)。封面比例跟真卡的 `cardRatio` 对番号
+ 作品给的那一档一致:显式筛了竖屏是 9:16,首页与 JAV 语境下选了大图是 3:4 正封,
+ 其余 16:9。首页大图只拉长番号作品,骨架不知道会回来哪几张,按版式本身给。 */
+function catalogSkeletonHtml(label='正在读取作品'){
+ return pageSkeletonHtml(label,{cards:true,className:'catalog-skeleton postercard-skeleton',cardRatio:catalogCardRatio()});
+}
+function catalogCardRatio(){
+ if(!state)return 16/9;
+ const layout=catalogGridLayout();
+ if(layout.portrait)return 9/16;
+ return layout.active&&layout.size==='big'?COVER_FRONT_RATIO:16/9;
+}
/* 挂着卡片网格的几处:目录 `#grid`、资料页作品区、详情页的接着看。 */
function gridIslandHosts(){
return [$('#grid'),...$('#index').querySelectorAll('[data-entity-grid]'),$('#nrow')].filter(host=>islandMounted(host));
@@ -8287,7 +8297,7 @@ function catalogGridProps(){
mode:'catalog',helpers:gridHelpers,actions:gridActions,layout:catalogGridLayout(),
selectMode,selected:new Set(selected),seekSeconds:appSettings.seekSeconds,revision:catalogRevision,
cache,wireDrag,settled:settleCatalog,
- skeletonHtml:()=>pageSkeletonHtml('正在读取作品',{cards:true,className:'catalog-skeleton postercard-skeleton'}),
+ skeletonHtml:()=>catalogSkeletonHtml(),
filters:{...state},batchSize:appSettings.batchSize,groupCollapse:appSettings.groupCollapse,
/* 只有首页默认列表排除竖屏——那里另有独立的竖屏带承接它们。搜索必须能搜到竖屏作品,
否则按名字找一条竖屏视频会得到 0 结果。JAV 模式恒不含竖屏:番号发行物本身就是横版。 */
diff --git a/web/css/09-skeleton.css b/web/css/09-skeleton.css
index 45e045a5f..d2fadf23d 100644
--- a/web/css/09-skeleton.css
+++ b/web/css/09-skeleton.css
@@ -22,7 +22,7 @@
.skeletoncard{display:grid;gap:10px;min-width:0}
.skeletoncard i,.skeletoncard b,.skeletoncard em{display:block;
border-radius:var(--control-radius);background:var(--hover)}
-.skeletoncard i{aspect-ratio:16/9}.skeletoncard b{width:72%;height:18px}.skeletoncard em{width:46%;height:14px}
+.skeletoncard i{aspect-ratio:var(--skeleton-card-ratio,16/9)}.skeletoncard b{width:72%;height:18px}.skeletoncard em{width:46%;height:14px}
/* 头像格与标签格只有海报网格用得上,行政界面的骨架照 fieldset 排,多出来的两格
会在一列长条中间凭空插两块灰。默认关掉,由用得上的那张骨架自己打开。 */
.skeletoncard s,.skeletoncard u{display:none}
diff --git a/web/js/ui-components.js b/web/js/ui-components.js
index ae2c68314..097243eac 100644
--- a/web/js/ui-components.js
+++ b/web/js/ui-components.js
@@ -659,8 +659,10 @@ export function loadingDotsHtml(label='正在处理', {className=''}={}){
/** Geist Skeleton: reserve a large content region while its structure is loading. */
/* `count` 只对 cards 生效:块数是骨架说出口的结构预告,六块对上的是海报网格,
- 而行政界面往往只有两三个大区。多画的块加载完就消失,那不是占位是误报。 */
-export function skeletonHtml(label='正在读取内容',{className='',variant='panel',count=6,fill=true,gridClass='',gridSize=''}={}){
+ 而行政界面往往只有两三个大区。多画的块加载完就消失,那不是占位是误报。
+ `cardRatio` 是卡片封面的宽高比,交给调用方按真卡的版式给:大图版式的正封是竖的,
+ 骨架照 16:9 铺的话,内容一到整屏卡片都要被拉高一截。 */
+export function skeletonHtml(label='正在读取内容',{className='',variant='panel',count=6,fill=true,gridClass='',gridSize='',cardRatio=0}={}){
const kind=new Set(['panel','cards','dashboard']).has(variant)?variant:'panel';
const body=kind==='cards'
?Array.from({length:Math.max(1,count)},
@@ -682,7 +684,8 @@ export function skeletonHtml(label='正在读取内容',{className='',variant='p
return `<div class="skeletonpanel skeleton-${kind}${className?` ${esc(className)}`:''}"
data-skeleton="${esc(kind)}${className?`/${esc(className)}`:''}"${kind==='cards'&&fill?' data-fill=""':''}
role="status" aria-label="${esc(label)}"><span class="sr-only">${esc(label)}</span>
- <div${gridClass?` class="${esc(gridClass)}"`:''}${gridSize?` data-size="${esc(gridSize)}"`:''} aria-hidden="true">${body}</div></div>`;
+ <div${gridClass?` class="${esc(gridClass)}"`:''}${gridSize?` data-size="${esc(gridSize)}"`:''}${
+ kind==='cards'&&Number(cardRatio)>0?` style="--skeleton-card-ratio:${Number(cardRatio)}"`:''} aria-hidden="true">${body}</div></div>`;
}
/** 索引占位复用最终网格、头像和词表的尺寸。 */