From 4b474df00e047ad7c1e015214ad6af63f1a72961 Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:00:19 +0100 Subject: [PATCH 01/15] RelatedArticles --- .../relatedArticles/relatedArticles.xml | 15 +++++++++++++ .../parts/relatedArticles/relatedArticles.ts | 22 +++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml b/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml index b001a3b4a..947517faa 100644 --- a/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml +++ b/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml @@ -1,6 +1,21 @@ Relaterte artikler
+ + + + + + Standard valg er å hente artikkel med lik dato som publiseringsdato for statistikken, ved å velge Siste artikkel for statistikken henter den sist publiserte artikkel som er tilknyttet statistikken + + + + + + default + + + diff --git a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts index 896afa682..09c7473f0 100644 --- a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts +++ b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts @@ -99,7 +99,6 @@ function renderPart(req: XP.Request, relatedArticles: RelatedArticles['relatedAr height: 180, }) } else { - // use placeholder if there is no seo image on the article const image: string = articleContent.x['com-enonic-app-metafields']?.['meta-data']?.seoImage imageSrc = imageUrl({ id: image, @@ -192,6 +191,7 @@ function addDsArticle( ): RelatedArticles['relatedArticles'] { const statisticId: string = page._id const statisticData: Statistics = page.data as Statistics + const dsArticleType: string = statisticData.dsArticle === 'lastArticle' ? 'lastArticle' : 'default' const statistic: StatisticInListing | undefined = getStatisticByIdFromRepo(statisticData.statistic) if (statistic) { @@ -200,23 +200,31 @@ function addDsArticle( const nextRelease: string = releaseDates.nextRelease[0] const previousRelease: string = releaseDates.previousRelease[0] const statisticPublishDate: string = showPreview && nextRelease !== '' ? nextRelease : previousRelease - const assosiatedArticle: RelatedArticle | undefined = getDsArticle(statisticId, statisticPublishDate) - if (assosiatedArticle && relatedArticles) { - relatedArticles.unshift(assosiatedArticle) + const associatedArticle: RelatedArticle | undefined = getDsArticle(statisticId, statisticPublishDate, dsArticleType) + + if (associatedArticle && relatedArticles) { + relatedArticles.unshift(associatedArticle) } } return relatedArticles } -function getDsArticle(statisticId: string, statisticPublishDate: string): RelatedArticle | undefined { +function getDsArticle( + statisticId: string, + statisticPublishDate: string, + dsArticleType: string +): RelatedArticle | undefined { statisticPublishDate = statisticPublishDate ? new Date(statisticPublishDate).toLocaleDateString() : '' + const queryString = `data.associatedStatistics.XP.content = "${statisticId}" AND publish.from LIKE "${statisticPublishDate}*" ` + const sort = dsArticleType === 'lastArticle' ? 'publish.from DESC' : 'publish.from ASC' + const articleContent: Array> = query({ count: 1, - sort: 'publish.from DESC', - query: `data.associatedStatistics.XP.content = "${statisticId}" AND publish.from LIKE "${statisticPublishDate}*" `, + sort, + query: queryString, contentTypes: [`${app.name}:article`], }).hits as unknown as Array> From 0cba0a81290d0c0c887eb2681d81c70d9e27edf7 Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:32:01 +0100 Subject: [PATCH 02/15] Xml endringer i statistics.xml --- .../content-types/statistics/statistics.xml | 17 ++++++++++++++++- .../mixins/relatedArticles/relatedArticles.xml | 15 --------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/resources/site/content-types/statistics/statistics.xml b/src/main/resources/site/content-types/statistics/statistics.xml index f2e0d8aad..dd8936277 100644 --- a/src/main/resources/site/content-types/statistics/statistics.xml +++ b/src/main/resources/site/content-types/statistics/statistics.xml @@ -113,9 +113,24 @@ + + + + + + Standard valg er å hente artikkel med lik dato som publiseringsdato for statistikken, ved å velge Siste artikkel for statistikken henter den sist publiserte artikkel som er tilknyttet statistikken + + + + + + default + + + + - diff --git a/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml b/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml index 947517faa..b001a3b4a 100644 --- a/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml +++ b/src/main/resources/site/mixins/relatedArticles/relatedArticles.xml @@ -1,21 +1,6 @@ Relaterte artikler - - - - - - Standard valg er å hente artikkel med lik dato som publiseringsdato for statistikken, ved å velge Siste artikkel for statistikken henter den sist publiserte artikkel som er tilknyttet statistikken - - - - - - default - - - From 7636dc3e83cbfa03aacb50777e69475b2c1c36fe Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:47:07 +0100 Subject: [PATCH 03/15] queryString - dsArticleType --- .../resources/site/parts/relatedArticles/relatedArticles.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts index 09c7473f0..d7b471526 100644 --- a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts +++ b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts @@ -218,7 +218,11 @@ function getDsArticle( ): RelatedArticle | undefined { statisticPublishDate = statisticPublishDate ? new Date(statisticPublishDate).toLocaleDateString() : '' - const queryString = `data.associatedStatistics.XP.content = "${statisticId}" AND publish.from LIKE "${statisticPublishDate}*" ` + const queryString = + dsArticleType === 'lastArticle' + ? `data.associatedStatistics.XP.content = "${statisticId}"` + : `data.associatedStatistics.XP.content = "${statisticId}" AND publish.from LIKE "${statisticPublishDate}*" ` + const sort = dsArticleType === 'lastArticle' ? 'publish.from DESC' : 'publish.from ASC' const articleContent: Array> = query({ From 77b70f2f1553bd08f9ed5f9bea58ab5096e0cbb4 Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:53:40 +0100 Subject: [PATCH 04/15] cleaner sort --- .../resources/site/parts/relatedArticles/relatedArticles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts index d7b471526..47610d941 100644 --- a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts +++ b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts @@ -223,7 +223,7 @@ function getDsArticle( ? `data.associatedStatistics.XP.content = "${statisticId}"` : `data.associatedStatistics.XP.content = "${statisticId}" AND publish.from LIKE "${statisticPublishDate}*" ` - const sort = dsArticleType === 'lastArticle' ? 'publish.from DESC' : 'publish.from ASC' + const sort = 'publish.from DESC' const articleContent: Array> = query({ count: 1, From aaceedb231c764985c1ec202a3d2dad33a3bcb00 Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:01:10 +0100 Subject: [PATCH 05/15] Changes to RelatedArticles.ts --- .../resources/site/parts/relatedArticles/relatedArticles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts index 47610d941..a7cfd920f 100644 --- a/src/main/resources/site/parts/relatedArticles/relatedArticles.ts +++ b/src/main/resources/site/parts/relatedArticles/relatedArticles.ts @@ -191,7 +191,7 @@ function addDsArticle( ): RelatedArticles['relatedArticles'] { const statisticId: string = page._id const statisticData: Statistics = page.data as Statistics - const dsArticleType: string = statisticData.dsArticle === 'lastArticle' ? 'lastArticle' : 'default' + const dsArticleType: string = statisticData.dsArticle ?? 'default' const statistic: StatisticInListing | undefined = getStatisticByIdFromRepo(statisticData.statistic) if (statistic) { From 197e3d7bf89bdee625a2323d3596f6bd7bfdd29c Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:28:00 +0100 Subject: [PATCH 06/15] xml fix --- .../resources/site/content-types/statistics/statistics.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/site/content-types/statistics/statistics.xml b/src/main/resources/site/content-types/statistics/statistics.xml index dd8936277..0c5cd1d3e 100644 --- a/src/main/resources/site/content-types/statistics/statistics.xml +++ b/src/main/resources/site/content-types/statistics/statistics.xml @@ -113,6 +113,8 @@ + + @@ -129,8 +131,6 @@ - - From 0d356a7afa92a5bdcf6a51212b319de98e8641a5 Mon Sep 17 00:00:00 2001 From: Carina <47381367+ssb-cgn@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:32:06 +0100 Subject: [PATCH 07/15] Merge pull request #3068 from statisticsnorway/develop (#3070) From 309e1582543b50707df85ba0865b87c892920749 Mon Sep 17 00:00:00 2001 From: Carina <47381367+ssb-cgn@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:52:01 +0100 Subject: [PATCH 08/15] [MIM-2141] Mim 2141 rss news 90 days (#3066) * Added days to getNews * Refactoring and removed loglines * Refactoring Code --- src/main/resources/lib/ssb/rss/news.ts | 40 ++++++++----------- .../resources/lib/ssb/statreg/statistics.ts | 22 +++++++++- .../resources/services/rssNews/rssNews.ts | 3 +- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/main/resources/lib/ssb/rss/news.ts b/src/main/resources/lib/ssb/rss/news.ts index f221cb130..ed346e4f6 100644 --- a/src/main/resources/lib/ssb/rss/news.ts +++ b/src/main/resources/lib/ssb/rss/news.ts @@ -1,9 +1,10 @@ import { query, type Content } from '/lib/xp/content' import { StatisticInListing, VariantInListing } from '/lib/ssb/dashboard/statreg/types' import { getTimeZoneIso } from '/lib/ssb/utils/dateUtils' -import { subDays, isSameDay, format, parseISO } from '/lib/vendor/dateFns' -import { fetchStatisticsWithReleaseToday } from '/lib/ssb/statreg/statistics' +import { subDays, format, parseISO } from '/lib/vendor/dateFns' +import { fetchStatisticsWithReleaseToday, fetchStatisticsDaysBack } from '/lib/ssb/statreg/statistics' import { getMainSubjects } from '/lib/ssb/utils/subjectUtils' +import { nextReleasedPassed } from '/lib/ssb/utils/variantUtils' // @ts-ignore import { xmlEscape } from '/lib/text-encoding' import { type SubjectItem } from '/lib/types/subject' @@ -14,8 +15,8 @@ const dummyReq: Partial = { branch: 'master', } -export function getRssItemsNews(): string | null { - const news: NewsItem[] = getNews() +export function getRssItemsNews(days: number = 1): string | null { + const news: NewsItem[] = getNews(days) const xml = ` ${news @@ -37,15 +38,15 @@ export function getRssItemsNews(): string | null { return xml } -export function getNews(): NewsItem[] { +export function getNews(days: number = 1): NewsItem[] { const mainSubjects: SubjectItem[] = getMainSubjects(dummyReq as XP.Request) - const articles: NewsItem[] = getArticles(mainSubjects) - const statistics: NewsItem[] = getStatistics(mainSubjects) + const articles: NewsItem[] = getArticles(mainSubjects, days) + const statistics: NewsItem[] = getStatistics(mainSubjects, days) return articles.concat(statistics) } -function getArticles(mainSubjects: SubjectItem[]): NewsItem[] { - const from: string = subDays(new Date(), 1).toISOString() +function getArticles(mainSubjects: SubjectItem[], days: number): NewsItem[] { + const from: string = subDays(new Date(), days).toISOString() const to: string = new Date().toISOString() const serverOffsetInMilliSeconds: number = parseInt(app.config?.['serverOffsetInMs']) || 0 const timeZoneIso: string = getTimeZoneIso(serverOffsetInMilliSeconds) @@ -93,8 +94,9 @@ function getArticles(mainSubjects: SubjectItem[]): NewsItem[] { return news } -function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] { - const statregStatistics: Array = fetchStatisticsWithReleaseToday() +function getStatistics(mainSubjects: SubjectItem[], days: number): NewsItem[] { + const statregStatistics: Array = + days > 1 ? fetchStatisticsDaysBack(days) : fetchStatisticsWithReleaseToday() const serverOffsetInMS: number = parseInt(app.config?.['serverOffsetInMs']) || 0 const timeZoneIso: string = getTimeZoneIso(serverOffsetInMS) @@ -114,6 +116,7 @@ function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] { ) const variant: VariantInListing | undefined = statreg?.variants?.[0] || undefined const pubDate: string | undefined = variant ? getPubDateStatistic(variant, timeZoneIso) : undefined + const link = getLinkByPath(statistic._path) if (pubDate) { statisticsNews.push({ @@ -136,18 +139,9 @@ function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] { } function getPubDateStatistic(variant: VariantInListing, timeZoneIso: string): string | undefined { - const previousReleaseSameDayNow: boolean = variant.previousRelease - ? isSameDay(new Date(variant.previousRelease), new Date()) - : false - const nextReleaseSameDayNow: boolean = variant.nextRelease - ? isSameDay(new Date(variant.nextRelease), new Date()) - : false - if (previousReleaseSameDayNow) { - return variant.previousRelease ? formatPubDateStatistic(variant.previousRelease, timeZoneIso) : undefined - } else if (nextReleaseSameDayNow) { - return variant.nextRelease ? formatPubDateStatistic(variant.nextRelease, timeZoneIso) : undefined - } - return undefined + const nextReleaseDatePassed: boolean = variant.nextRelease ? nextReleasedPassed(variant) : false + const pubDate: string | undefined = nextReleaseDatePassed ? variant.nextRelease : variant.previousRelease + return pubDate ? formatPubDateStatistic(pubDate, timeZoneIso) : undefined } function formatPubDateArticle(date: string, serverOffsetInMS: number, timeZoneIso: string): string { diff --git a/src/main/resources/lib/ssb/statreg/statistics.ts b/src/main/resources/lib/ssb/statreg/statistics.ts index 7ec3bf451..1cb645fed 100644 --- a/src/main/resources/lib/ssb/statreg/statistics.ts +++ b/src/main/resources/lib/ssb/statreg/statistics.ts @@ -7,7 +7,7 @@ import { ReleaseDatesVariant, } from '/lib/ssb/dashboard/statreg/types' import { HttpResponse } from '/lib/http-client' -import { format, isSameDay, isAfter } from '/lib/vendor/dateFns' +import { format, isSameDay, isAfter, subDays, isBefore } from '/lib/vendor/dateFns' import { isDateBetween } from '/lib/ssb/utils/dateUtils' import { ensureArray } from '/lib/ssb/utils/arrayUtils' @@ -114,6 +114,26 @@ export function fetchStatisticsWithReleaseToday(): Array { }, []) } +export function fetchStatisticsDaysBack(days: number): Array { + const statistics: Array = getAllStatisticsFromRepo() + const serverOffsetInMs: number = app.config?.['serverOffsetInMs'] ? parseInt(app.config['serverOffsetInMs']) : 0 + const now: Date = new Date(new Date().getTime() + serverOffsetInMs) + const from = subDays(new Date(), days) + return statistics.reduce((statsWithRelease: Array, stat) => { + const variants: Array = ensureArray(stat.variants).filter( + (variant) => + (isAfter(new Date(variant.nextRelease), from) && isBefore(new Date(variant.nextRelease), now)) || + isAfter(new Date(variant.previousRelease), from) + ) + + if (variants.length > 0) { + stat.variants = variants + statsWithRelease.push(stat) + } + return statsWithRelease + }, []) +} + //TODO: Remove possibly unused code export function fetchStatisticsWithPreviousReleaseBetween(from: Date, to: Date): Array { const statistics: Array = getAllStatisticsFromRepo() diff --git a/src/main/resources/services/rssNews/rssNews.ts b/src/main/resources/services/rssNews/rssNews.ts index 91498ed99..ed983a778 100644 --- a/src/main/resources/services/rssNews/rssNews.ts +++ b/src/main/resources/services/rssNews/rssNews.ts @@ -2,9 +2,10 @@ import { getNews, getRssItemsNews } from '/lib/ssb/rss/news' export function get(req: XP.Request): XP.Response { const format: string = req.params.format ?? 'json' + const days: string = req.params.days ?? '90' const isXml = format === 'xml' return { - body: isXml ? getRssItemsNews() : getNews(), + body: isXml ? getRssItemsNews(Number(days)) : getNews(Number(days)), contentType: isXml ? 'text/xml' : 'application/json', } } From 1b9a2e0504f47dca7b1819110f7f13f6e99c8ac5 Mon Sep 17 00:00:00 2001 From: Carina <47381367+ssb-cgn@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:31:03 +0100 Subject: [PATCH 09/15] [MIM-1964] MIM-1964:Fixed imageUrl if only two pictureCard (#3072) MIM-1964:Fixed imageUrl if only two pictureCard --- .../site/parts/pictureCardLinks/pictureCardLinks.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/resources/site/parts/pictureCardLinks/pictureCardLinks.ts b/src/main/resources/site/parts/pictureCardLinks/pictureCardLinks.ts index e0641174a..f005c8ab8 100644 --- a/src/main/resources/site/parts/pictureCardLinks/pictureCardLinks.ts +++ b/src/main/resources/site/parts/pictureCardLinks/pictureCardLinks.ts @@ -49,7 +49,7 @@ function parsePictureCardLinks( const subTitle: string = pictureCardLink.subTitle const href: string = pictureCardLink.href - const imageSources = createImageUrls(pictureCardLink, i) + const imageSources = createImageUrls(pictureCardLink, pictureCardLinks.length, i) const pictureCardLinksContent: PictureCardLinksContent = { title: title, @@ -63,7 +63,7 @@ function parsePictureCardLinks( }, []) } -function createImageUrls(pictureCardLink: PictureCardLink, i: number): ImageUrls { +function createImageUrls(pictureCardLink: PictureCardLink, listLength: number, i: number): ImageUrls { const imageUrls: ImageUrls = { portraitSrcSet: '', landscapeSrcSet: '', @@ -78,7 +78,11 @@ function createImageUrls(pictureCardLink: PictureCardLink, i: number): ImageUrls }) imageUrls.landscapeSrcSet = imageUrls.imageSrc - if (i > 0) imageUrls.portraitSrcSet = imageUrls.imageSrc.replace('block-580-400', 'block-280-400') + + if (listLength === 4 || (listLength === 3 && i > 0)) { + imageUrls.portraitSrcSet = imageUrls.imageSrc.replace('block-580-400', 'block-280-400') + } + imageUrls.imageAlt = getImageAlt(pictureCardLink.image) || '' } else { imageUrls.imageSrc = imagePlaceholder({ From 01c613ccfa418b6e89a5fa365f80014a3d4d6c6f Mon Sep 17 00:00:00 2001 From: jrn-ssb Date: Tue, 17 Dec 2024 12:48:33 +0100 Subject: [PATCH 10/15] Update dataSource.xml (#3059) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helga Marie tester å endre hjelpetekster med Magnus. --- src/main/resources/site/mixins/dataSource/dataSource.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/site/mixins/dataSource/dataSource.xml b/src/main/resources/site/mixins/dataSource/dataSource.xml index 7f3dab319..b1f121bae 100644 --- a/src/main/resources/site/mixins/dataSource/dataSource.xml +++ b/src/main/resources/site/mixins/dataSource/dataSource.xml @@ -8,6 +8,7 @@