diff --git a/package.json b/package.json index d31257a2..13a5ecd4 100644 --- a/package.json +++ b/package.json @@ -25,13 +25,13 @@ "@headlessui/react": "^2.2.0", "@heroicons/react": "^2.2.0", "@icons-pack/react-simple-icons": "^12.3.0", - "@js-temporal/polyfill": "^0.4.4", "@jsdevtools/rehype-url-inspector": "^2.0.2", "@octokit/core": "^6.1.4", "@shikijs/transformers": "^3.2.1", "@sindresorhus/slugify": "^2.2.1", "@wpengine/atlas-next": "^2.0.1", "date-fns": "^4.1.0", + "date-fns-tz": "^3.2.0", "downshift": "^9.0.9", "feed": "^4.2.2", "graphql": "^16.10.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 548879f3..b9d6a883 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,9 +32,6 @@ importers: '@icons-pack/react-simple-icons': specifier: ^12.3.0 version: 12.3.0(react@19.0.0) - '@js-temporal/polyfill': - specifier: ^0.4.4 - version: 0.4.4 '@jsdevtools/rehype-url-inspector': specifier: ^2.0.2 version: 2.0.2 @@ -53,6 +50,9 @@ importers: date-fns: specifier: ^4.1.0 version: 4.1.0 + date-fns-tz: + specifier: ^3.2.0 + version: 3.2.0(date-fns@4.1.0) downshift: specifier: ^9.0.9 version: 9.0.9(react@19.0.0) @@ -571,10 +571,6 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} - '@js-temporal/polyfill@0.4.4': - resolution: {integrity: sha512-2X6bvghJ/JAoZO52lbgyAPFj8uCflhTo2g7nkFzEQdXd/D8rEeD4HtmTEpmtGCva260fcd66YNXBOYdnmHqSOg==} - engines: {node: '>=12'} - '@jsdevtools/rehype-url-inspector@2.0.2': resolution: {integrity: sha512-iQL2lb+nOoT+5jFz1nfOa3oBJPF2JyBtPQgGmrRhxLT3QZAGIMLz/mh/9mUmk7FfKF5NB8xq0KoLn5F4/QHpyA==} engines: {node: '>=10'} @@ -1675,6 +1671,11 @@ packages: resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==} engines: {node: '>= 0.4'} + date-fns-tz@3.2.0: + resolution: {integrity: sha512-sg8HqoTEulcbbbVXeg84u5UnlsQa8GS5QXMqjjYIhS4abEVVKIUwe0/l/UhrZdKaL/W5eWZNlbTeEIiOXTcsBQ==} + peerDependencies: + date-fns: ^3.0.0 || ^4.0.0 + date-fns@4.1.0: resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==} @@ -2741,9 +2742,6 @@ packages: resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} hasBin: true - jsbi@4.3.0: - resolution: {integrity: sha512-SnZNcinB4RIcnEyZqFPdGPVgrg2AcnykiBy0sHVJQKHYeaLUvi3Exj+iaPpLnFVkDPZIV4U0yvgC9/R4uEAZ9g==} - jsdoc-type-pratt-parser@4.1.0: resolution: {integrity: sha512-Hicd6JK5Njt2QB6XYFS7ok9e37O8AYk3jTcppG4YVQnYjOemymvTcmc7OWsmq/Qqj5TdRFO5/x/tIPmBeRtGHg==} engines: {node: '>=12.0.0'} @@ -4948,11 +4946,6 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 - '@js-temporal/polyfill@0.4.4': - dependencies: - jsbi: 4.3.0 - tslib: 2.8.1 - '@jsdevtools/rehype-url-inspector@2.0.2': dependencies: url-regex: 5.0.0 @@ -6211,6 +6204,10 @@ snapshots: es-errors: 1.3.0 is-data-view: 1.0.2 + date-fns-tz@3.2.0(date-fns@4.1.0): + dependencies: + date-fns: 4.1.0 + date-fns@4.1.0: {} debug@3.2.7: @@ -7609,8 +7606,6 @@ snapshots: dependencies: argparse: 2.0.1 - jsbi@4.3.0: {} - jsdoc-type-pratt-parser@4.1.0: {} jsesc@3.0.2: {} diff --git a/src/lib/feed.js b/src/lib/feed.js index 1e86553a..31a8ee39 100644 --- a/src/lib/feed.js +++ b/src/lib/feed.js @@ -1,7 +1,7 @@ import { env } from "node:process"; import { URL } from "node:url"; import { gql } from "@apollo/client"; -import { Temporal } from "@js-temporal/polyfill"; +import { format } from "date-fns-tz"; import { Feed } from "feed"; const SITE_URL = env.NEXT_PUBLIC_SITE_URL; @@ -56,9 +56,9 @@ export function createFeed({ feed_data, last_modified }) { language: "en", image: new URL("/favicon-192x192.png", SITE_URL).href, favicon: new URL("/favicon-32x32.png", SITE_URL).href, - copyright: Temporal.Now.plainDateISO( - feed_data.generalSettings.timezone, - ).year.toString(), + copyright: format(new Date(), "yyyy", { + timeZone: feed_data.generalSettings.timezone, + }), updated: new Date(last_modified.toString()), feedLinks: { json: new URL("/api/feeds/feed.json", SITE_URL).href, diff --git a/src/pages/api/feeds/[feed-type].js b/src/pages/api/feeds/[feed-type].js index 4abc87a9..2fd77527 100644 --- a/src/pages/api/feeds/[feed-type].js +++ b/src/pages/api/feeds/[feed-type].js @@ -1,6 +1,6 @@ import { createHash } from "node:crypto"; import { getApolloClient } from "@faustwp/core/dist/mjs/client"; -import { Temporal } from "@js-temporal/polyfill"; +import { parseISO, compareAsc } from "date-fns"; // Replaced Temporal with date-fns import { StatusCodes, getReasonPhrase } from "http-status-codes"; import { FEED_QUERY, createFeed } from "@/lib/feed"; @@ -18,12 +18,9 @@ export default async function HandleFeeds(req, res) { query: FEED_QUERY, }); - const last_modified = Temporal.PlainDateTime.from( + const last_modified = parseISO( feed_data.last_modified.nodes[0].modifiedGmt, - { - overflow: "constrain", - }, - ); + ); // Replaced Temporal.PlainDateTime.from // Create feed const feed = createFeed({ feed_data, last_modified }); @@ -75,14 +72,14 @@ export default async function HandleFeeds(req, res) { ); res.setHeader("Content-Type", resp.content_type); res.setHeader("ETag", etag_for_body); - res.setHeader("Last-Modified", last_modified.toString()); + res.setHeader("Last-Modified", last_modified.toUTCString()); // Adjusted to use Date's toUTCString() if ( // Checks if the `if_none_match` header matches current response' etag if_none_match === etag_for_body || // Checks `if_modified_since` is after `last_modified` (if_modified_since && - Temporal.PlainDateTime.compare(last_modified, if_modified_since) < 0) + compareAsc(last_modified, new Date(if_modified_since)) < 0) // Replaced Temporal.PlainDateTime.compare ) { res.status(StatusCodes.NOT_MODIFIED); res.end();