Skip to content

Commit a894358

Browse files
committed
Fix Norwegian link #3484 #3479
1 parent 5fd275d commit a894358

10 files changed

Lines changed: 56 additions & 28 deletions

File tree

web/core/ImageWithOverlay/ImageWithOverlay.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ export const ImageWithOverlay = forwardRef<
134134
...action?.file,
135135
label: action?.label,
136136
}}
137-
{...(action.link?.lang && {
138-
locale: getLocaleFromName(action.link?.lang),
139-
})}
140137
type={action.type}
141138
variant='fit'
142139
>

web/lib/helpers/getUrlFromAction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type { LinkData } from '../../types/index'
1+
import { defaultLanguage } from 'languageConfig'
2+
import type { LinkData, MenuLinkData } from '../../types/index'
3+
import { getLocaleFromName } from 'sanity/helpers/localization'
24

35
export const getUrlFromAction = ({
46
link,
@@ -10,12 +12,14 @@ export const getUrlFromAction = ({
1012
if (!type && !href) return undefined
1113

1214
const anchor = anchorReference ? `#${anchorReference}` : ''
15+
const locale = link?.lang !== defaultLanguage.name? getLocaleFromName(link?.lang) :""
16+
1317

1418
if (type === 'internalUrl') {
1519
if (!link?.slug) {
1620
console.warn('Missing slug in action:', fileName)
1721
}
18-
return link?.slug + anchor || ''
22+
return ("/"+locale+ link?.slug + anchor) || ''
1923
}
2024

2125
if (!href && type !== 'downloadableFile') {

web/sections/CallToActions/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const CallToActions = ({
3939
label,
4040
}}
4141
href={url}
42-
{...(link?.lang && { hrefLang: getLocaleFromName(link?.lang) })}
4342
type={type}
4443
variant='fit'
4544
>
@@ -71,9 +70,6 @@ const CallToActions = ({
7170
label,
7271
}}
7372
href={url}
74-
{...(link?.lang && {
75-
hrefLang: getLocaleFromName(link?.lang),
76-
})}
7773
type={type}
7874
variant={linkVariant ? linkVariant : 'default'}
7975
>

web/sections/LatestNews/LatestNews.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
'use client'
2-
import { useTranslations } from 'next-intl'
2+
import { useLocale, useTranslations } from 'next-intl'
33
import FormattedDateTime from '@/core/FormattedDateTime/FormattedDateTime'
44
import { Promotion } from '@/core/Promotion/Promotion'
55
import { Typography } from '@/core/Typography'
66
import type { CardData } from '../../types/index'
7+
import { defaultLanguage } from '@/languageConfig'
8+
import { getLocaleFromIso } from '@/sanity/helpers/localization'
79

810
type LatestNewsProp = {
911
data: CardData[]
1012
}
1113

1214
const LatestNews = ({ data }: LatestNewsProp) => {
1315
const t = useTranslations()
14-
16+
const iso = useLocale()
1517
return (
1618
<section className='flex w-full flex-col items-start 3xl:px-layout-md px-layout-sm py-20'>
1719
<Typography variant='h2' className='mb-10'>
@@ -20,6 +22,9 @@ const LatestNews = ({ data }: LatestNewsProp) => {
2022
{/*grid auto-rows-fr grid-cols-1 gap-x-6 gap-y-3 max-lg:w-full md:auto-cols-fr md:grid-flow-col*/}
2123
<ul className='flex w-full flex-col gap-6 lg:grid lg:grid-cols-3'>
2224
{data.map((newsItem: CardData) => {
25+
26+
const locale = iso!== defaultLanguage.name? getLocaleFromIso(iso) :""
27+
const href = newsItem?.slug && ("/"+locale+ newsItem?.slug) || ''
2328
return (
2429
<li key={newsItem.id}>
2530
<Promotion
@@ -39,7 +44,7 @@ const LatestNews = ({ data }: LatestNewsProp) => {
3944
),
4045
})}
4146
image={newsItem?.heroImage?.image}
42-
href={newsItem?.slug}
47+
href={href}
4348
hasSectionTitle={true}
4449
/>
4550
</li>

web/sections/SiteMenu/FeaturedContent.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use client'
22
import type { PortableTextBlock } from '@portabletext/types'
3-
import { useTranslations } from 'next-intl'
3+
import { useLocale, useTranslations } from 'next-intl'
44
import { Banner } from '@/core/Banner/Banner'
55
import { Typography } from '@/core/Typography'
66
import { EventCard } from '@/sections/cards/EventCard'
77
import type { FeaturedContentData } from '../../types/index'
88
import type { EventCardData } from '../cards/EventCard/EventCard'
9+
import { defaultLanguage } from '@/languageConfig'
10+
import { getLocaleFromIso } from '@/sanity/helpers/localization'
911

1012
type Props = {
1113
featuredContent: FeaturedContentData
@@ -25,6 +27,9 @@ const FeaturedContent = ({
2527
data?.routeContentType === 'event'
2628
const { type, heroImage, title, ingress, slug } = featuredContent
2729

30+
const iso = useLocale()
31+
const locale = iso!== defaultLanguage.name? getLocaleFromIso(iso) :""
32+
const href = ("/"+locale+ slug) || ''
2833
return (
2934
<div className=''>
3035
<Typography
@@ -54,7 +59,7 @@ const FeaturedContent = ({
5459
//@ts-ignore:TODO - find out why any[] and not portabletext[]
5560
title={title}
5661
ingress={ingress ?? featuredIngress}
57-
ctaLink={slug}
62+
ctaLink={href}
5863
ctaLabel={featuredCTALabel}
5964
/>
6065
)}

web/sections/SiteMenu/MenuItem.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ import type {
1111
SubMenuGroupData,
1212
} from '../../types/index'
1313
import FeaturedContent from './FeaturedContent'
14+
import { useLocale } from 'next-intl'
15+
import { getLocaleFromIso } from '@/sanity/helpers/localization'
16+
import { defaultLanguage } from '@/languageConfig'
1417

1518
const { MenuItem: _MenuItem, MenuHeader, MenuContent } = Menu
1619

17-
function getLink(linkData: MenuLinkData) {
20+
function getLink(menuLinkData: MenuLinkData, iso:string) {
1821
// Fallback to home page, if this happens it is an error somewhere
1922
// Sanity should take care of the validation here, and this is temp. until
2023
// the static pages are migrated
21-
if (!linkData) return 'something-wrong'
22-
const { link } = linkData
23-
24-
return link?.slug || '/'
24+
if (!menuLinkData) return 'something-wrong'
25+
// manually setting lang here.. as menu links only allow same language links..
26+
const locale = iso!== defaultLanguage.name? getLocaleFromIso(iso) :""
27+
return ("/"+locale+ menuLinkData.link?.slug) || ''
2528
}
2629

2730
type MenuGroupType = {
@@ -39,7 +42,8 @@ export const MenuItem = ({ item, index }: MenuGroupType) => {
3942
featuredIngress,
4043
} = item
4144

42-
const menuItemHref = getLink(topLevelLink)
45+
const iso = useLocale()
46+
const menuItemHref = getLink(topLevelLink,iso)
4347

4448
const pathname = usePathname()
4549

@@ -91,7 +95,7 @@ export const MenuItem = ({ item, index }: MenuGroupType) => {
9195
<li key={link.id}>
9296
<Link
9397
className={`relative py-2 text-sm no-underline underline-offset-2 hover:underline ${ariaCurrentStyling} `}
94-
href={getLink(link)}
98+
href={getLink(link,iso)|| "/"}
9599
aria-current={
96100
pathname === link?.link?.slug ? 'page' : 'false'
97101
}

web/sections/cards/EventCard/EventCard.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Icon } from '@equinor/eds-core-react'
33
import { world } from '@equinor/eds-icons'
44
import { toPlainText } from '@portabletext/react'
55
import type { PortableTextBlock } from '@portabletext/types'
6-
import { useFormatter, useTranslations } from 'next-intl'
6+
import { useFormatter, useLocale, useTranslations } from 'next-intl'
77
import { forwardRef, type HTMLAttributes } from 'react'
88
import { twMerge } from 'tailwind-merge'
99
import FormattedDateTime, {
@@ -18,6 +18,8 @@ import {
1818
} from '@/styles/colorKeyToUtilityMap'
1919
import AddToCalendar from '../../../core/AddToCalendar/AddToCalendar'
2020
import Blocks from '../../../portableText/Blocks'
21+
import { defaultLanguage } from '@/languageConfig'
22+
import { getLocaleFromIso } from '@/sanity/helpers/localization'
2123

2224
type Variants = 'default' | 'single' | 'carousel'
2325

@@ -71,6 +73,10 @@ const EventCard = forwardRef<HTMLDivElement, EventCardProps>(function EventCard(
7173
endDayAndTime,
7274
} = data
7375

76+
const iso = useLocale()
77+
const locale = iso!== defaultLanguage.name? getLocaleFromIso(iso) :""
78+
const href = ("/"+locale+ slug) || ''
79+
7480
const formatter = useFormatter()
7581
const { start, end } = getEventDates(eventDate)
7682
const { dayTime: startDayTime, overrideTimeLabel: startTimeLabel } =
@@ -93,7 +99,7 @@ const EventCard = forwardRef<HTMLDivElement, EventCardProps>(function EventCard(
9399
className,
94100
)}
95101
>
96-
<BaseLink href={slug} className='mb-6 hover:underline'>
102+
<BaseLink href={href} className='mb-6 hover:underline'>
97103
<Blocks
98104
value={title}
99105
as={hasSectionTitle ? 'h3' : 'h2'}

web/templates/newsroom/NewsSections/NewsHeadliner.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Typography } from '@/core/Typography'
88
import { getSmallerThanPxLgSizes, Image } from '../../../core/Image/Image'
99
import Blocks from '../../../portableText/Blocks'
1010
import type { NewsRoomNewsItem } from '../../../types/algoliaIndexPage'
11+
import { defaultLanguage } from '@/languageConfig'
12+
import { useLocale } from 'next-intl'
13+
import { getLocaleFromIso } from '@/sanity/helpers/localization'
1114

1215
export type NewsHeadlinerProps = {
1316
data: NewsRoomNewsItem
@@ -21,10 +24,11 @@ const NewsHeadliner = forwardRef<HTMLLIElement, NewsHeadlinerProps>(
2124
) {
2225
const { slug, title, ingress, publishDateTime, heroImage, thumbnailUrl } =
2326
data
24-
27+
const lang = useLocale()
28+
const locale = getLocaleFromIso(lang)
2529
return (
2630
<section ref={ref} {...rest} className={twMerge('', className)}>
27-
<BaseLink href={slug} className='group flex flex-col gap-2 pb-6'>
31+
<BaseLink href={`${locale!=defaultLanguage.locale? `/${locale}`: ""}${slug}`} className='group flex flex-col gap-2 pb-6'>
2832
{(heroImage?.image?.asset || fallbackImage || thumbnailUrl) && (
2933
<div className='relative mb-2 aspect-video max-h-[324px]'>
3034
{thumbnailUrl ? (

web/templates/newsroom/NewsSections/NewsItem.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { getSmallerThanPxLgSizes, Image } from '@/core/Image/Image'
66
import { BaseLink } from '@/core/Link/BaseLink'
77
import { Typography } from '@/core/Typography'
88
import type { NewsRoomNewsItem } from '@/types/algoliaIndexPage'
9+
import { useLocale } from 'next-intl'
10+
import { getLocaleFromIso } from '@/sanity/helpers/localization'
11+
import { defaultLanguage } from '@/languageConfig'
912

1013
export type NewsListItemProps = {
1114
data: NewsRoomNewsItem
@@ -20,10 +23,13 @@ const NewsItem = forwardRef<HTMLLIElement, NewsListItemProps>(function NewsItem(
2023
const { slug, title, publishDateTime, heroImage, thumbnailUrl } = data || {}
2124
if (!slug) return null
2225

26+
const lang = useLocale()
27+
const locale = getLocaleFromIso(lang)
28+
2329
return (
2430
<section ref={ref} className={className}>
2531
<BaseLink
26-
href={slug}
32+
href={`${locale!=defaultLanguage.locale? `/${locale}`: ""}${slug}`}
2733
className='group flex justify-between gap-4 lg:gap-6'
2834
>
2935
<div className='max-w-[65%]'>

web/templates/newsroom/Newsroom.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type { NewsRoomPageType } from '../../types'
2525
import NewsRoomFilters from './Filters/NewsroomFilters'
2626
import NewsSections from './NewsSections/NewsSections'
2727
import QuickSearch from './QuickSearch/QuickSearch'
28+
import { defaultLanguage } from '@/languageConfig'
2829

2930
type NewsRouteState = {
3031
query?: string
@@ -202,7 +203,7 @@ const NewsRoomTemplate = forwardRef<HTMLDivElement, NewsRoomTemplateProps>(
202203
>
203204
<List.Item className='w-full'>
204205
{subscriptionLink?.link?.slug && (
205-
<ResourceLink href={subscriptionLink.link.slug}>
206+
<ResourceLink href={`${locale!=defaultLanguage.locale? `/${locale}`: ""}${subscriptionLink.link.slug}`}>
206207
{subscriptionLinkTitle}
207208
</ResourceLink>
208209
)}
@@ -217,7 +218,7 @@ const NewsRoomTemplate = forwardRef<HTMLDivElement, NewsRoomTemplateProps>(
217218
>
218219
<ResourceLink
219220
type={localNewsPage.type}
220-
href={localNewsPage?.link?.slug}
221+
href={`${locale!=defaultLanguage.locale? `/${locale}`: ""}${localNewsPage?.link?.slug}`}
221222
>
222223
{localNewsPage?.label}
223224
</ResourceLink>

0 commit comments

Comments
 (0)