-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 🎨 sanity newsroom * 🎨 fix direction * 🎨 add norwegian route
- Loading branch information
1 parent
054b875
commit 2df4b0e
Showing
11 changed files
with
532 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getNameFromLocale } from '../../../lib/localization' | ||
import { sanityClient } from '../../../lib/sanity.server' | ||
import { getNewsArticlesByPage } from '../../../lib/queries/newsroom' | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const lang = req.query.lang === 'no' ? getNameFromLocale('no') : getNameFromLocale('en') // Defaults to 'en' if the lang parameter is not 'no' | ||
|
||
console.log('get next from req.query.lastId', req.query.lastId) | ||
console.log('get next from req.query.lastPublishedAt', req.query.lastPublishedAt) | ||
try { | ||
const news = await sanityClient.fetch(getNewsArticlesByPage(false, true), { | ||
lang, | ||
lastId: req.query.lastId, | ||
lastPublishedAt: req.query.lastPublishedAt, | ||
}) | ||
res.status(200).json({ news: news }) | ||
} catch (err) { | ||
res.status(500).json({ error: 'Failed to fetch news' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getNameFromLocale } from '../../../lib/localization' | ||
import { sanityClient } from '../../../lib/sanity.server' | ||
import { getNewsArticlesByPage } from '../../../lib/queries/newsroom' | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const lang = req.query.lang === 'no' ? getNameFromLocale('no') : getNameFromLocale('en') // Defaults to 'en' if the lang parameter is not 'no' | ||
|
||
try { | ||
const news = await sanityClient.fetch(getNewsArticlesByPage(true, false), { | ||
lang, | ||
lastId: req.query.lastId, | ||
lastPublishedAt: req.query.lastPublishedAt, | ||
}) | ||
res.status(200).json({ news: news }) | ||
} catch (err) { | ||
res.status(500).json({ error: 'Failed to fetch news' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { FormattedDate } from '@components/FormattedDateTime' | ||
import { forwardRef, HTMLAttributes } from 'react' | ||
import { BaseLink } from '@core/Link' | ||
import { Typography } from '@core/Typography' | ||
import Image, { Ratios } from '../../../pageComponents/shared/SanityImage' | ||
import envisTwMerge from '../../../twMerge' | ||
import { NewsRoomNewsItem } from '../../../types/algoliaIndexPage' | ||
import { SanityImageObject } from '@sanity/image-url/lib/types/types' | ||
import Blocks from '../../../pageComponents/shared/portableText/Blocks' | ||
|
||
export type NewsHeadlinerProps = { | ||
data: NewsRoomNewsItem | ||
fallbackImage?: SanityImageObject | ||
} & HTMLAttributes<HTMLLIElement> | ||
|
||
const NewsHeadlinerSanity = forwardRef<HTMLLIElement, NewsHeadlinerProps>(function NewsHeadlinerSanity( | ||
{ data, fallbackImage, className = '', ...rest }, | ||
ref, | ||
) { | ||
const { slug, title, ingress, publishDateTime, heroImage, tags, countryTags } = data | ||
|
||
return ( | ||
<section ref={ref} {...rest} className={envisTwMerge('', className)}> | ||
<BaseLink href={slug} className="group flex flex-col gap-2 pb-6"> | ||
{(heroImage?.image?.asset || fallbackImage) && ( | ||
<div className="aspect-video relative max-h-[324px] mb-2"> | ||
<Image | ||
//@ts-ignore: TODO Fix SanityImage to take SanityImageObject | ||
image={heroImage?.image?.asset ? heroImage?.image : fallbackImage} | ||
fill | ||
priority | ||
aspectRatio={Ratios.NINE_TO_SIXTEEN} | ||
sizes="(max-width: 800px) 100vw, 1440px" | ||
className="rounded-xs" | ||
aria-hidden | ||
/> | ||
</div> | ||
)} | ||
{publishDateTime && ( | ||
<FormattedDate datetime={publishDateTime} uppercase className="pt-4 text-2xs font-normal leading-normal" /> | ||
)} | ||
{title && ( | ||
<Typography as="h2" variant="lg" className="pb-6 group-hover:underline"> | ||
{title} | ||
</Typography> | ||
)} | ||
<div className="pb-2 flex gap-3 text-xs divide-x-2 divide-energy-red-100"> | ||
{tags?.map((tag: any, i: number) => { | ||
return ( | ||
<span key={tag.label} className=" text-xs inline-block text-grey-60 pl-3 pr-3 first:pl-0"> | ||
{tag.label} | ||
{i < tags.length - 1 && <span className="sr-only">,</span>} | ||
</span> | ||
) | ||
})} | ||
{countryTags?.length > 0 && <span className="sr-only">,</span>} | ||
{countryTags?.map((country: any, i: number) => { | ||
return ( | ||
<span key={country.label} className=" inline-block text-grey-60 pl-3 pr-3 first:pl-0"> | ||
{country.label} | ||
{i < countryTags.length - 1 && <span className="sr-only">,</span>} | ||
</span> | ||
) | ||
})} | ||
</div> | ||
{Array.isArray(ingress) ? ( | ||
<Blocks value={ingress} className="text-sm max-w-prose" /> | ||
) : ( | ||
<Typography variant="body" className="text-sm max-w-prose`"> | ||
{ingress} | ||
</Typography> | ||
)} | ||
</BaseLink> | ||
</section> | ||
) | ||
}) | ||
export default NewsHeadlinerSanity |
Oops, something went wrong.