0de33ad541
Memind CI / Test, build, and release guards (push) Successful in 4m9s
看板筛选期内的总访问/SEO/GEO 与 Umami memind-pages 取较大值,MindSpace 直链-only 的 public 页也会追加到目录。 Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import {
|
|
buildCatalogUmamiMatchKeys,
|
|
buildUmamiOnlyCatalogRow,
|
|
mergePublicationStatsWithUmami,
|
|
parseMindSpaceWorkspacePublicPath,
|
|
resolveUmamiStatsForMatchKeys,
|
|
} from './mindspace-seo-geo-umami-stats.mjs';
|
|
|
|
test('buildCatalogUmamiMatchKeys includes MindSpace workspace path and public url', () => {
|
|
const keys = buildCatalogUmamiMatchKeys({
|
|
userId: 'user-1',
|
|
publicUrl: '/u/john/pages/news',
|
|
workspaceRelativePath: 'public/daily-news-0917.html',
|
|
publicHost: 'm.tkmind.cn',
|
|
});
|
|
assert.ok(keys.includes('/MindSpace/user-1/public/daily-news-0917.html'));
|
|
assert.ok(keys.includes('/u/john/pages/news'));
|
|
});
|
|
|
|
test('mergePublicationStatsWithUmami prefers higher counts from either source', () => {
|
|
assert.deepEqual(
|
|
mergePublicationStatsWithUmami(
|
|
{ totalViews: 1, seoViews: 0, geoViews: 0, crawlerViews: 2 },
|
|
{ totalViews: 8, seoViews: 5, geoViews: 1 },
|
|
),
|
|
{ totalViews: 8, seoViews: 5, geoViews: 1, crawlerViews: 2 },
|
|
);
|
|
});
|
|
|
|
test('resolveUmamiStatsForMatchKeys merges multiple path aliases', () => {
|
|
const map = new Map([
|
|
['/MindSpace/user-1/public/daily-news-0917.html', { totalViews: 10, seoViews: 6, geoViews: 1 }],
|
|
]);
|
|
const stats = resolveUmamiStatsForMatchKeys(
|
|
['/u/john/pages/news', '/MindSpace/user-1/public/daily-news-0917.html'],
|
|
map,
|
|
);
|
|
assert.deepEqual(stats, { totalViews: 10, seoViews: 6, geoViews: 1 });
|
|
});
|
|
|
|
test('buildUmamiOnlyCatalogRow creates workspace-only catalog entry', () => {
|
|
const row = buildUmamiOnlyCatalogRow(
|
|
'/MindSpace/user-1/public/daily-news-0917.html',
|
|
{
|
|
totalViews: 12,
|
|
seoViews: 8,
|
|
geoViews: 1,
|
|
pageTitle: '每日新闻早报 · 2026年9月17日',
|
|
ownerLabel: 'John',
|
|
generatedAt: 5000,
|
|
},
|
|
);
|
|
assert.equal(row.publicationId, 'umami:/MindSpace/user-1/public/daily-news-0917.html');
|
|
assert.equal(row.seoViews, 8);
|
|
assert.equal(row.statsSource, 'umami');
|
|
assert.match(row.publicUrl, /daily-news-0917\.html$/);
|
|
});
|
|
|
|
test('parseMindSpaceWorkspacePublicPath rejects non-workspace paths', () => {
|
|
assert.deepEqual(parseMindSpaceWorkspacePublicPath('/u/john/pages/news'), null);
|
|
assert.deepEqual(parseMindSpaceWorkspacePublicPath('/MindSpace/u1/public/a.html'), {
|
|
userId: 'u1',
|
|
workspaceRelativePath: 'public/a.html',
|
|
});
|
|
});
|