This commit is contained in:
谢宇宁
2026-11-06 00:13:27 +07:00
parent f65d10e998
commit 37411fcada
98 changed files with 958 additions and 4598 deletions
+7 -10
View File
@@ -65,7 +65,7 @@ test('configuration failures and missing permanent origins retain the last valid
test('cold starts never guess a canonical and the browser preserves the server identity',()=>{
const cold=seo.resolveSeoEnvironment({},[]);
assert.equal(cold.origin,'');assert.equal(cold.site.siteName,'禁果短剧');
assert.equal(cold.origin,'');assert.equal(cold.site.siteName,'黄果短剧');
const head=seo.buildPageHead('/shorts/','',cold,{totalCount:72});
assert.equal(head.canonical,undefined);assert.equal(head.jsonLd,undefined);assert.equal(head.next,undefined);
assert.equal(seo.clientSeoEnvironment(environment,{config:{foreverUrlAddr:'https://other.drama.test'},seoInfo:{webSiteName:'其他品牌'}}),environment);
@@ -87,13 +87,12 @@ test('canonical is query-free, every pagination page identifies itself, and firs
assert.equal(page('/shorts/page/1/',{totalCount:72}).canonical,'https://drama.example.net/shorts/');
const overflow=page('/shorts/page/4/',{totalCount:72,pageSize:24});assert.equal(overflow.canonical,undefined);assert.match(overflow.robots,/noindex/);assert.equal(overflow.previous,undefined);
for(const totalCount of [0,1,24]){const head=page('/shorts/',{totalCount});assert.equal(head.previous,undefined);assert.equal(head.next,undefined);}
const center=page('/member/center/',{totalCount:72});assert.equal(center.previous,undefined);assert.equal(center.next,undefined);
for(const totalCount of [-1,NaN,'72']){const head=page('/shorts/',{totalCount});assert.equal(head.next,undefined);}
});
test('private/tools/search/error pages do not inherit public canonical or indexability',()=>{
for(const path of ['/search/爱情/','/navigation/','/home-road/','/apps/','/unknown-page/']){const head=page(path);assert.match(head.robots,/noindex,follow/);assert.equal(head.canonical,undefined,path);}
for(const path of ['/member/center/','/member/likes/','/member/likes/page/2/','/member/favorites/page/2/','/info/deposit/','/info/feedback/'])assert.equal(page(path).robots,'noindex,nofollow',path);
for(const path of ['/member/center/','/member/likes/','/info/deposit/','/info/feedback/']){const head=page(path);assert.equal(head.robots,'noindex,follow',path);assert.equal(head.canonical,undefined,path);assert.equal(seo.pageResponseStatus(path,{}),404,path);}
assert.match(page('/shorts/',{},'?sort=2').robots,/noindex/);assert.equal(page('/shorts/',{},'?sort=2').canonical,undefined);
for(const content of [{failed:true},{missing:true},{unavailable:true}])assert.equal(page('/detail/9/',content).canonical,undefined);
for(const path of ['/info/about-us/','/info/privacy-policy/','/rank/hot/','/rank/new/','/rank/follow/'])assert.ok(page(path).canonical,path);
@@ -114,9 +113,9 @@ test('client navigation updates SSR head once and clears old canonical/OG URL/pa
assert.equal(doc.title,last.title);assert.equal(doc.value('meta[property="og:site_name"]'),'91剧场');
assert.equal(doc.value('link[rel="canonical"]'),last.canonical);assert.equal(doc.value('meta[property="og:url"]'),last.canonical);
assert.equal(doc.value('link[rel="next"]'),undefined);assert.equal(doc.value('link[rel="prev"]'),last.previous);
const privatePage=page('/info/deposit/');clientSeo.applyPageHead(privatePage,doc);
const privatePage=page('/unknown-page/');clientSeo.applyPageHead(privatePage,doc);
assert.equal(doc.value('link[rel="canonical"]'),undefined);assert.equal(doc.value('meta[property="og:url"]'),undefined);assert.equal(doc.value('link[rel="prev"]'),undefined);
assert.equal(doc.value('meta[name="robots"]'),'noindex,nofollow');assert.equal(doc.value('meta[name="googlebot"]'),'noindex,nofollow');
assert.equal(doc.value('meta[name="robots"]'),'noindex,follow');assert.equal(doc.value('meta[name="googlebot"]'),'noindex,follow');
assert.equal(doc.value('meta[name="twitter:title"]'),privatePage.title);
});
@@ -141,7 +140,7 @@ test('topic aliases and numeric ID variants share a primary canonical without ch
assert.equal(page('/search/007/').canonical,undefined);
});
test('empty public lists and comment pagination are noindex while preserving successful and error statuses',()=>{
test('empty public lists are noindex while preserving successful and error statuses; detail/play pages are not paginated',()=>{
for(const path of ['/shorts/','/topics/','/topics/7/','/theme/7/','/tag/9/','/rank/hot/']){
const content={totalCount:0},head=page(path,content);
assert.equal(head.robots,'noindex,follow',path);assert.equal(head.canonical,undefined);assert.equal(head.jsonLd,undefined);
@@ -153,10 +152,8 @@ test('empty public lists and comment pagination are noindex while preserving suc
const playable=seo.dramaSeoContent({id:9,title:'作品名'},{id:90,currentEpisode:3,videoUrl:'https://media.example.net/3.mp4'});
for(const [path,data] of [['/detail/9/',drama],['/play/9/90/',playable]]){
assert.ok(page(path,{...data,totalCount:0,pageSize:10}).robots.startsWith('index,'),path);
const content={...data,totalCount:35,pageSize:10},paged=page(path+'page/2/',content);
assert.equal(seo.pageResponseStatus(path+'page/2/',content),200);
assert.equal(paged.robots,'noindex,follow');
for(const key of ['canonical','previous','next','jsonLd'])assert.equal(paged[key],undefined,key);
const content={...data,totalCount:35,pageSize:10};
assert.equal(seo.pageResponseStatus(path+'page/2/',content),404,'detail and play pages no longer paginate comments');
}
});