@@ -3,7 +3,8 @@ import { algoliasearch } from 'algoliasearch'
33import type { Metadata } from 'next'
44import { unstable_cache } from 'next/cache'
55import dynamic from 'next/dynamic'
6- import { setRequestLocale } from 'next-intl/server'
6+ import { notFound } from 'next/navigation'
7+ import { locale as rootLocale } from 'next/root-params'
78import { algolia } from '@/lib/config'
89import { Flags } from '@/sanity/helpers/datasetHelpers'
910import { getNameFromIso } from '@/sanity/helpers/localization'
@@ -17,19 +18,8 @@ import NewsRoomTemplate from '@/templates/newsroom/Newsroom'
1718
1819const TopicPage = dynamic ( ( ) => import ( '@/templates/topic/TopicPage' ) )
1920
20- export async function generateStaticParams ( ) {
21- if ( Flags . HAS_NEWSROOM ) {
22- return [ { locale : 'en-GB' } ]
23- }
24- return [ ]
25- }
26-
27- export async function generateMetadata ( {
28- params,
29- } : {
30- params : Promise < { locale : string } >
31- } ) : Promise < Metadata > {
32- const { locale } = await params
21+ export async function generateMetadata ( ) : Promise < Metadata > {
22+ const locale = await rootLocale ( )
3323 const pageSlug = newsSlug [ getNameFromIso ( locale ) ]
3424 if ( Flags . HAS_NEWSROOM ) {
3525 const { data : metaData } : { data : any } = await routeSanityFetch ( {
@@ -47,48 +37,41 @@ export async function generateMetadata({
4737 return constructSanityMetadata ( pageSlug , locale , undefined )
4838}
4939
50- const getInitialResponse = unstable_cache (
51- // this gets revalidated by path
52- async ( locale : string ) => {
53- const envPrefix = Flags . IS_GLOBAL_PROD ? 'prod' : 'dev'
54- const indexName = `${ envPrefix } _NEWS_${ locale } `
40+ export default async function NewsroomPage ( _ : PageProps < '/[locale]/news' > ) {
41+ const locale = await rootLocale ( )
5542
56- console . log (
57- new Date ( ) ,
58- 'Fetching initial response for' ,
59- indexName ,
60- 'after revalidation' ,
61- )
62- const searchClient = algoliasearch (
63- algolia . applicationId ,
64- algolia . searchApiKey ,
65- )
66- const response = await searchClient . searchSingleIndex ( {
67- indexName : indexName ,
68- searchParams : {
69- hitsPerPage : 50 ,
70- facetFilters : [ 'type:news' , 'topicTags:-Crude Oil Assays' ] ,
71- facetingAfterDistinct : true ,
72- facets : [ 'countryTags' , 'topicTags' , 'year' ] ,
73- } ,
74- } )
75- return response
76- } ,
77- undefined ,
78- {
79- tags : [ `newsroom_en-GB` ] ,
80- } ,
81- )
82-
83- export default async function NewsroomPage ( {
84- params,
85- } : {
86- params : Promise < { slug : string ; locale : string } >
87- } ) {
88- const { locale, slug } = await params
89- // Enable static rendering
90- setRequestLocale ( locale )
43+ const getInitialResponse = unstable_cache (
44+ // this gets revalidated by path
45+ async ( ) => {
46+ const envPrefix = Flags . IS_GLOBAL_PROD ? 'prod' : 'dev'
47+ const indexName = `${ envPrefix } _NEWS_${ locale } `
9148
49+ console . log (
50+ new Date ( ) ,
51+ 'Fetching initial response for' ,
52+ indexName ,
53+ 'after revalidation' ,
54+ )
55+ const searchClient = algoliasearch (
56+ algolia . applicationId ,
57+ algolia . searchApiKey ,
58+ )
59+ const response = await searchClient . searchSingleIndex ( {
60+ indexName : indexName ,
61+ searchParams : {
62+ hitsPerPage : 50 ,
63+ facetFilters : [ 'type:news' , 'topicTags:-Crude Oil Assays' ] ,
64+ facetingAfterDistinct : true ,
65+ facets : [ 'countryTags' , 'topicTags' , 'year' ] ,
66+ } ,
67+ } )
68+ return response
69+ } ,
70+ undefined ,
71+ {
72+ tags : [ `newsroom` , await locale ] ,
73+ } ,
74+ )
9275 const [ siteMenuResult , pageResults ] = await Promise . all ( [
9376 routeSanityFetch ( {
9477 query : Flags . HAS_FANCY_MENU ? globalMenuQuery : simpleMenuQuery ,
@@ -97,7 +80,7 @@ export default async function NewsroomPage({
9780 } ,
9881 } ) ,
9982 getPage ( {
100- slug : slug ?? newsSlug [ getNameFromIso ( locale ) ] ,
83+ slug : newsSlug [ getNameFromIso ( locale ) ] ,
10184 locale,
10285 tags : [ 'newsroom' ] ,
10386 } ) ,
@@ -106,9 +89,10 @@ export default async function NewsroomPage({
10689 const { headerData, pageData } = pageResults
10790 const { data : siteMenuData } = siteMenuResult || { }
10891
109- const response = Flags . HAS_NEWSROOM
110- ? await getInitialResponse ( locale )
111- : undefined
92+ const response =
93+ Flags . HAS_NEWSROOM && locale in [ 'en-GB' , 'nb-NO' ]
94+ ? await getInitialResponse ( )
95+ : undefined
11296
11397 return (
11498 < >
0 commit comments