From 396d755005c51951c498f8da7360746dd0cf5c63 Mon Sep 17 00:00:00 2001 From: sora Date: Wed, 12 Jan 2022 19:20:10 -0800 Subject: [PATCH] fix timestamp error --- .../src/plugins/lib/__tests__/merge.test.ts | 24 +------------------ .../feed-builder/src/plugins/lib/merge.ts | 5 ---- .../src/plugins/synthetic-publish-time.ts | 4 ++-- 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/packages/feed-builder/src/plugins/lib/__tests__/merge.test.ts b/packages/feed-builder/src/plugins/lib/__tests__/merge.test.ts index 45a573e..67033dc 100644 --- a/packages/feed-builder/src/plugins/lib/__tests__/merge.test.ts +++ b/packages/feed-builder/src/plugins/lib/__tests__/merge.test.ts @@ -23,28 +23,6 @@ describe("Util/Merge", () => { }); it("Feed/Metadata update", async () => { - const existing: JsonFeed = { - version: "Mock version", - title: "Mock title", - description: "Mock description", - items: [], - }; - - const incoming: JsonFeed = { - version: "Mock version", - title: "Mock title new", - description: "Mock description new", - items: [], - }; - - const merged = mergeJsonFeed(incoming, existing); - - await expect(merged.items.length).toEqual(0); - await expect(merged.title).toEqual("Mock title new"); - await expect(merged.description).toEqual("Mock description new"); - }); - - it("Feed/Metadata update/Persist publish time", async () => { const existing: JsonFeed = { version: "Mock version", title: "Mock title", @@ -70,7 +48,7 @@ describe("Util/Merge", () => { await expect(merged.items.length).toEqual(0); await expect(merged.title).toEqual("Mock title new"); await expect(merged.description).toEqual("Mock description new"); - await expect(merged._ext.date_published).toEqual("2000-01-01T00:00:00Z"); + await expect(merged._ext.date_published).toEqual("2000-01-02T00:00:00Z"); }); it("Items/Addition", async () => { diff --git a/packages/feed-builder/src/plugins/lib/merge.ts b/packages/feed-builder/src/plugins/lib/merge.ts index 03ff8fd..2264abf 100644 --- a/packages/feed-builder/src/plugins/lib/merge.ts +++ b/packages/feed-builder/src/plugins/lib/merge.ts @@ -4,11 +4,6 @@ export function mergeJsonFeed(newFeed: T, existingFeed: T): return { ...existingFeed, ...newFeed, - _ext: { - ...existingFeed._ext, - ...newFeed._ext, - date_published: existingFeed._ext?.date_published ?? newFeed._ext?.date_published, // publish timestamp is considered immutable - }, items: mergeFeedItems(newFeed.items, existingFeed.items, mergeItems).sort(sortItems), }; } diff --git a/packages/feed-builder/src/plugins/synthetic-publish-time.ts b/packages/feed-builder/src/plugins/synthetic-publish-time.ts index fc02c1e..fcb3dcb 100644 --- a/packages/feed-builder/src/plugins/synthetic-publish-time.ts +++ b/packages/feed-builder/src/plugins/synthetic-publish-time.ts @@ -33,10 +33,10 @@ export function useSyntheticPublishTime(): Plugin { _ext: { ...feed._ext, date_published: - (feed as ParsedJsonFeed)._ext?.date_published ?? - (feed as ParsedJsonFeed)._ext?.date_modified ?? feed.items[0]?.date_published ?? feed.items[0]?.date_modified ?? + (feed as ParsedJsonFeed)._ext?.date_published ?? + (feed as ParsedJsonFeed)._ext?.date_modified ?? new Date().toISOString(), }, })),