@rmdes/indiekit-endpoint-blogroll 1.0.22 → 1.0.24

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/index.js CHANGED
@@ -7,6 +7,7 @@ import { blogsController } from "./lib/controllers/blogs.js";
7
7
  import { sourcesController } from "./lib/controllers/sources.js";
8
8
  import { apiController } from "./lib/controllers/api.js";
9
9
  import { startSync, stopSync } from "./lib/sync/scheduler.js";
10
+ import { waitForReady } from "@rmdes/indiekit-startup-gate";
10
11
 
11
12
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
13
 
@@ -142,11 +143,15 @@ export default class BlogrollEndpoint {
142
143
 
143
144
  // Start background sync if database is available
144
145
  if (Indiekit.config.application.mongodbUrl) {
145
- startSync(Indiekit, this.options);
146
+ this._stopGate = waitForReady(
147
+ () => startSync(Indiekit, this.options),
148
+ { label: "Blogroll" },
149
+ );
146
150
  }
147
151
  }
148
152
 
149
153
  destroy() {
154
+ this._stopGate?.();
150
155
  stopSync();
151
156
  }
152
157
  }
@@ -234,6 +234,7 @@ function sanitizeBlog(blog) {
234
234
  itemCount: blog.itemCount,
235
235
  pinned: blog.pinned,
236
236
  lastFetchAt: blog.lastFetchAt,
237
+ lastItemAt: blog.lastItemAt || null,
237
238
  source: blog.source || null,
238
239
  };
239
240
 
@@ -110,6 +110,7 @@ export async function createBlog(application, data) {
110
110
  author: data.author || null,
111
111
  status: "active",
112
112
  lastFetchAt: null,
113
+ lastItemAt: null,
113
114
  lastError: null,
114
115
  itemCount: 0,
115
116
  pinned: data.pinned || false,
@@ -200,6 +201,7 @@ export async function updateBlogStatus(application, id, status) {
200
201
  if (status.itemCount !== undefined) {
201
202
  update.itemCount = status.itemCount;
202
203
  }
204
+ if (status.lastItemAt) update.lastItemAt = status.lastItemAt;
203
205
  if (status.title) update.title = status.title;
204
206
  if (status.photo) update.photo = status.photo;
205
207
  if (status.siteUrl) update.siteUrl = status.siteUrl;
@@ -289,6 +291,7 @@ export async function upsertBlog(application, data) {
289
291
  if (data.skipItemFetch !== undefined) setFields.skipItemFetch = data.skipItemFetch;
290
292
  if (data.photo !== undefined) setFields.photo = data.photo;
291
293
  if (data.lastFetchAt !== undefined) setFields.lastFetchAt = data.lastFetchAt;
294
+ if (data.lastItemAt !== undefined) setFields.lastItemAt = data.lastItemAt;
292
295
  if (data.status !== undefined) setFields.status = data.status;
293
296
 
294
297
  // $setOnInsert only for fields NOT already in $set (avoids MongoDB path conflicts)
@@ -312,6 +315,7 @@ export async function upsertBlog(application, data) {
312
315
  if (!("skipItemFetch" in setFields)) insertDefaults.skipItemFetch = false;
313
316
  if (!("photo" in setFields)) insertDefaults.photo = null;
314
317
  if (!("lastFetchAt" in setFields)) insertDefaults.lastFetchAt = null;
318
+ if (!("lastItemAt" in setFields)) insertDefaults.lastItemAt = null;
315
319
  if (!("status" in setFields)) insertDefaults.status = "active";
316
320
 
317
321
  const result = await collection.updateOne(
package/lib/sync/feed.js CHANGED
@@ -307,10 +307,19 @@ export async function syncBlogItems(application, blog, options = {}) {
307
307
  if (result.upserted) added++;
308
308
  }
309
309
 
310
+ // Compute newest item publish date
311
+ let newestDate = null;
312
+ for (const item of feed.items) {
313
+ if (item.published && (!newestDate || item.published > newestDate)) {
314
+ newestDate = item.published;
315
+ }
316
+ }
317
+
310
318
  // Update blog metadata
311
319
  const updateData = {
312
320
  success: true,
313
321
  itemCount: feed.items.length,
322
+ lastItemAt: newestDate,
314
323
  };
315
324
 
316
325
  // Update title if not manually set (still has feedUrl as title)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-blogroll",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "Blogroll endpoint for Indiekit. Aggregates blog feeds from OPML, JSON feeds, or manual entry.",
5
5
  "keywords": [
6
6
  "indiekit",
@@ -40,6 +40,7 @@
40
40
  "index.js"
41
41
  ],
42
42
  "dependencies": {
43
+ "@rmdes/indiekit-startup-gate": "^1.0.0",
43
44
  "@indiekit/error": "^1.0.0-beta.25",
44
45
  "@indiekit/frontend": "^1.0.0-beta.25",
45
46
  "express": "^5.0.0",