Skip to content

Commit d3cda12

Browse files
authored
Date format in newsletter and fix newsletter on modify #3543 (#3544)
1 parent 3899db3 commit d3cda12

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

web/lib/queries/common/publishDateTime.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,3 @@ export const publishDateTimeQuery = /* groq */ `
99
export const lastUpdatedTimeQuery = /* groq */ `
1010
coalesce(lastModifiedAt,_updatedAt)
1111
`
12-
13-
export const newsletterPublishDateTimeQuery = /* groq */ `
14-
select(
15-
customPublicationDate == true =>
16-
publishDateTime,
17-
coalesce(_updatedAt, firstPublishedAt, _createdAt)
18-
)
19-
`

web/pages/api/newsletter-rss/groq.global.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { ImageWithCaptionData } from '../../../types'
1+
2+
import { functions } from '../../../lib/queries/common/functions'
23
import { ingressForNewsQuery } from '../../../lib/queries/common/newsSubqueries'
3-
import { newsletterPublishDateTimeQuery } from '../../../lib/queries/common/publishDateTime'
4-
import { PortableTextBlock } from '@portabletext/types'
4+
import { publishDateTimeQuery } from '../../../lib/queries/common/publishDateTime'
55
import { noDrafts, sameLang } from '../../../lib/queries/common/langAndDrafts'
6-
import { functions } from '../../../lib/queries/common/functions'
6+
import type { ImageWithCaptionData } from '../../../types'
7+
import type { PortableTextBlock } from '@portabletext/types'
78

89
export type LatestNewsType = {
910
_id: string
@@ -21,27 +22,27 @@ export type LatestNewsType = {
2122

2223
export const latestNews = /* groq */ `
2324
${functions}
24-
*[_type == "news" && defined(subscriptionType) && ${sameLang} && ${noDrafts}] | order(${newsletterPublishDateTimeQuery} desc)[0...5] {
25+
*[_type == "news" && defined(subscriptionType) && ${sameLang} && ${noDrafts}] | order(${publishDateTimeQuery} desc)[0...5] {
2526
_id,
2627
"type":_type,
2728
"slug": slug.current,
2829
title,
2930
"hero": heroImage,
3031
subscriptionType,
31-
"publishDateTime": ${newsletterPublishDateTimeQuery},
32+
"publishDateTime": ${publishDateTimeQuery},
3233
${ingressForNewsQuery},
3334
lang
3435
}
3536
`
3637
export const latestMagazine = /* groq */ `
3738
${functions}
38-
*[_type == "magazine" && shouldDistributeMagazine && ${sameLang} && ${noDrafts}] | order(${newsletterPublishDateTimeQuery} desc)[0...5] {
39+
*[_type == "magazine" && shouldDistributeMagazine && ${sameLang} && ${noDrafts}] | order(${publishDateTimeQuery} desc)[0...5] {
3940
_id,
4041
"type":_type,
4142
"slug": slug.current,
4243
title,
4344
"hero": heroFigure,
44-
"publishDateTime": ${newsletterPublishDateTimeQuery},
45+
"publishDateTime": ${publishDateTimeQuery},
4546
${ingressForNewsQuery},
4647
lang
4748
}

web/pages/api/newsletter-rss/index.global.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ const generateRssFeed = async (locale: 'en_GB' | 'nb_NO') => {
4949
const publishDate = new Date(article.publishDateTime).toUTCString()
5050
console.log('article.publishDateTime', article.publishDateTime)
5151
console.log('publishDate', publishDate)
52+
const dateFormat = article.lang === 'nb_NO' ? 'd. MMMM yyyy hh:mm' : 'd MMMM yyyy hh:mm'
53+
54+
const getTimezoneAbbreviation = (date: Date, timeZone: string) => {
55+
const parts = new Intl.DateTimeFormat('en-GB', {
56+
timeZone,
57+
timeZoneName: 'short',
58+
}).formatToParts(date)
59+
60+
const tzPart = parts.find((p) => p.type === 'timeZoneName')
61+
62+
// TS-safe: fallback in case it's undefined
63+
return tzPart?.value ?? ''
64+
}
5265

5366
// Format the main pubDate
5467
//const formattedPubDate = //format(new TZDate(publishDate, 'Europe/Oslo'), 'EEE, dd MMM yyyy HH:mm:ss xxxx')
@@ -64,9 +77,14 @@ const generateRssFeed = async (locale: 'en_GB' | 'nb_NO') => {
6477
<pubDate>${publishDate}</pubDate>
6578
<description>${toPlainText(article.ingress)}</description>
6679
${categoryTag ? `<category>${mapCategoryToId(categoryTag, locale)}</category>` : '<category />'}
67-
<nl:extra1>${format(new TZDate(publishDate, 'Europe/Oslo'), "d.MMMM yyyy hh:mm ('CEST')", {
68-
locale: article.lang === 'nb_NO' ? nb : enGB,
69-
})}</nl:extra1>
80+
<nl:extra1>${
81+
format(new TZDate(publishDate, 'Europe/Oslo'), dateFormat, {
82+
locale: article.lang === 'nb_NO' ? nb : enGB,
83+
}) +
84+
' (' +
85+
getTimezoneAbbreviation(new TZDate(publishDate, 'Europe/Oslo'), 'Europe/Oslo') +
86+
')'
87+
}</nl:extra1>
7088
${
7189
hero?.image?.asset
7290
? `<media:content medium="image" type="image/jpeg" url="${encodedUrl}">

0 commit comments

Comments
 (0)