@yourbright/emdash-analytics-plugin 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +8 -63
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -297,27 +297,6 @@ async function getManagedContentMap(siteOrigin) {
|
|
|
297
297
|
void siteOrigin;
|
|
298
298
|
return managed;
|
|
299
299
|
}
|
|
300
|
-
async function resolveManagedContent(collection, id, slug, siteOrigin) {
|
|
301
|
-
if (collection !== "posts") return null;
|
|
302
|
-
const ref = id || slug;
|
|
303
|
-
if (!ref) return null;
|
|
304
|
-
const result = await getEmDashEntry("posts", ref);
|
|
305
|
-
const entry = result.entry;
|
|
306
|
-
if (!entry) return null;
|
|
307
|
-
const entryId = typeof entry.id === "string" ? entry.id : ref;
|
|
308
|
-
const entrySlug = typeof entry.slug === "string" ? entry.slug : null;
|
|
309
|
-
const data = entry.data ?? {};
|
|
310
|
-
const urlPath = `/blog/${entrySlug || entryId}/`;
|
|
311
|
-
return {
|
|
312
|
-
collection: "posts",
|
|
313
|
-
id: entryId,
|
|
314
|
-
slug: entrySlug,
|
|
315
|
-
urlPath,
|
|
316
|
-
title: typeof data.title === "string" ? data.title : entrySlug || entryId,
|
|
317
|
-
excerpt: typeof data.excerpt === "string" ? data.excerpt : void 0,
|
|
318
|
-
seoDescription: typeof data.seo_description === "string" ? data.seo_description : void 0
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
300
|
function pageStorageId(urlPath) {
|
|
322
301
|
return stableStorageId(urlPath);
|
|
323
302
|
}
|
|
@@ -1073,15 +1052,7 @@ async function getContentContext(ctx, collection, id, slug) {
|
|
|
1073
1052
|
if (!page) {
|
|
1074
1053
|
throw new PluginRouteError("NOT_FOUND", "Analytics data not found for content", 404);
|
|
1075
1054
|
}
|
|
1076
|
-
const contentRef =
|
|
1077
|
-
collection: "posts",
|
|
1078
|
-
id: page.contentId || id || pageStorageId(page.urlPath),
|
|
1079
|
-
slug: page.contentSlug || slug || null,
|
|
1080
|
-
urlPath: page.urlPath,
|
|
1081
|
-
title: page.title,
|
|
1082
|
-
excerpt: void 0,
|
|
1083
|
-
seoDescription: void 0
|
|
1084
|
-
};
|
|
1055
|
+
const contentRef = resolveStoredContentRef(page, collection, id, slug);
|
|
1085
1056
|
const queries = await getFreshQueriesForPage(ctx, config, contentRef.urlPath);
|
|
1086
1057
|
const windows = buildWindows();
|
|
1087
1058
|
const score = scorePage(page, queries);
|
|
@@ -1215,49 +1186,23 @@ async function loadPage(ctx, urlPath) {
|
|
|
1215
1186
|
async function findContentPage(ctx, collection, id, slug) {
|
|
1216
1187
|
if (id) {
|
|
1217
1188
|
const byId = await ctx.storage.pages.query({
|
|
1218
|
-
where: {
|
|
1219
|
-
|
|
1220
|
-
contentId: id
|
|
1221
|
-
},
|
|
1222
|
-
limit: 1
|
|
1189
|
+
where: { contentId: id },
|
|
1190
|
+
limit: 20
|
|
1223
1191
|
});
|
|
1224
|
-
const match = byId.items
|
|
1192
|
+
const match = byId.items.map((item) => item.data).find((page) => page.contentCollection === collection);
|
|
1225
1193
|
if (match) return match;
|
|
1226
1194
|
}
|
|
1227
1195
|
if (slug) {
|
|
1228
1196
|
const bySlug = await ctx.storage.pages.query({
|
|
1229
|
-
where: {
|
|
1230
|
-
|
|
1231
|
-
contentSlug: slug
|
|
1232
|
-
},
|
|
1233
|
-
limit: 1
|
|
1197
|
+
where: { contentSlug: slug },
|
|
1198
|
+
limit: 20
|
|
1234
1199
|
});
|
|
1235
|
-
const match = bySlug.items
|
|
1200
|
+
const match = bySlug.items.map((item) => item.data).find((page) => page.contentCollection === collection);
|
|
1236
1201
|
if (match) return match;
|
|
1237
1202
|
}
|
|
1238
1203
|
return null;
|
|
1239
1204
|
}
|
|
1240
|
-
|
|
1241
|
-
if (collection !== "posts") {
|
|
1242
|
-
return {
|
|
1243
|
-
collection: "posts",
|
|
1244
|
-
id: page.contentId || id || pageStorageId(page.urlPath),
|
|
1245
|
-
slug: page.contentSlug || slug || null,
|
|
1246
|
-
urlPath: page.urlPath,
|
|
1247
|
-
title: page.title,
|
|
1248
|
-
excerpt: void 0,
|
|
1249
|
-
seoDescription: void 0
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1252
|
-
const resolved = await resolveManagedContent(
|
|
1253
|
-
collection,
|
|
1254
|
-
page.contentId || id,
|
|
1255
|
-
page.contentSlug || slug || void 0,
|
|
1256
|
-
siteOrigin
|
|
1257
|
-
);
|
|
1258
|
-
if (resolved) {
|
|
1259
|
-
return resolved;
|
|
1260
|
-
}
|
|
1205
|
+
function resolveStoredContentRef(page, collection, id, slug) {
|
|
1261
1206
|
return {
|
|
1262
1207
|
collection: "posts",
|
|
1263
1208
|
id: page.contentId || id || pageStorageId(page.urlPath),
|