Skip to content

Commit

Permalink
Merge branch 'bose/2433' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle committed Sep 11, 2024
2 parents 84e9025 + 44839d2 commit 4f32e2e
Show file tree
Hide file tree
Showing 66 changed files with 9,623 additions and 2,842 deletions.
38 changes: 38 additions & 0 deletions sanityv3/schemas/documents/newsroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { file } from '@equinor/eds-icons'
import { EdsIcon } from '../../icons'
import type { PortableTextBlock, Rule } from 'sanity'
import { lang } from './langField'
import routes from '../routes'
import { filterByRoute } from '../../helpers/referenceFilters'

const titleContentType = configureTitleBlockContent()
const textContentType = configureBlockContent({
Expand Down Expand Up @@ -66,6 +68,42 @@ export default {
type: 'array',
of: [textContentType],
},
{
name: 'subscriptionLink',
title: 'Link to the email subscription page',
type: 'reference',
to: routes,
options: {
filter: filterByRoute,
},
},
{
name: 'subscriptionLinkTitle',
title: 'Title for the subscription link',
type: 'string',
},
{
title: 'List of local news pages',
name: 'localNewsPages',
type: 'array',
of: [{ type: 'linkSelector', title: 'Link' }],
},
{
title: 'Image thumbnail fallbacks',
name: 'imageThumbnailFallbacks',
type: 'array',
of: [
{
type: 'image',
title: 'Fallback image',
options: {
hotspot: true,
collapsed: false,
},
},
],
validation: (Rule: Rule) => Rule.max(3),
},
],
preview: {
select: {
Expand Down
80 changes: 80 additions & 0 deletions sanityv3/schemas/textSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ const snippets: textSnippet = {
defaultValue: 'Search',
group: groups.search,
},
search_quick_search: {
title: 'Quick search',
defaultValue: 'Quick search',
group: groups.search,
},
search_quick_search_label: {
title: 'Quick search label',
defaultValue: 'Search among Equinor corporate-level news releases',
group: groups.search,
},
search_news_tab: {
title: 'News tab name',
defaultValue: 'News',
Expand Down Expand Up @@ -116,6 +126,31 @@ const snippets: textSnippet = {
defaultValue: 'Sorry, no results were found. Please try again with some different keywords.',
group: groups.search,
},
search_submit: {
title: 'Submit search',
defaultValue: 'Submit search',
group: groups.search,
},
search_reset: {
title: 'Reset',
defaultValue: 'Reset',
group: groups.search,
},
search_filter_by: {
title: 'Filter by',
defaultValue: 'Filter by',
group: groups.search,
},
search_pagination_first_page: {
title: 'First page',
defaultValue: 'First page',
group: groups.search,
},
search_pagination_last_page: {
title: 'Last page',
defaultValue: 'Last page',
group: groups.search,
},
copyright: {
title: 'Copyright',
defaultValue: 'Copyright 2022 Equinor ASA',
Expand Down Expand Up @@ -672,6 +707,21 @@ const snippets: textSnippet = {
defaultValue: 'Topic',
group: groups.newsroom,
},
newsroom_filters_label: {
title: 'Filters label',
defaultValue: 'Filter by:',
group: groups.newsroom,
},
newsroom_filters_selected: {
title: 'Selected',
defaultValue: 'Selected',
group: groups.newsroom,
},
newsroom_filters_clear_all: {
title: 'Clear all',
defaultValue: 'Clear all',
group: groups.newsroom,
},
newsroom_country_filter: {
title: 'Country filter heading',
defaultValue: 'Country',
Expand Down Expand Up @@ -703,6 +753,16 @@ const snippets: textSnippet = {
defaultValue: 'Your search returned no results',
group: groups.newsroom,
},
newsroom_related_links: {
title: 'Related links',
defaultValue: 'Related links',
group: groups.newsroom,
},
newsroom_skip_to_news: {
title: 'Skip to list of news',
defaultValue: 'Skip to list of news',
group: groups.newsroom,
},
magazineindex_list_header: {
title: 'Magazine index: Stories list heading',
defaultValue: 'Stories',
Expand Down Expand Up @@ -749,6 +809,26 @@ const snippets: textSnippet = {
defaultValue: 'Switch to',
group: groups.others,
},
next: {
title: 'Next',
defaultValue: 'Next',
group: groups.others,
},
previous: {
title: 'Previous',
defaultValue: 'Previous',
group: groups.others,
},
page: {
title: 'Page',
defaultValue: 'Page',
group: groups.others,
},
remove: {
title: 'Remove',
defaultValue: 'Remove',
group: groups.others,
},
}

type textSnippetGroup = { title: string; hidden?: boolean }
Expand Down
2 changes: 2 additions & 0 deletions search/IndexSanityContent/common/news/SharedNewsFields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Page } from '../../../common'
import { ImageWithAltAndCaption } from '../types'

export type SharedNewsFields = Page & {
title: string
Expand All @@ -18,4 +19,5 @@ export type SharedNewsFields = Page & {
text: string
}[]
_id: string
heroImage?: ImageWithAltAndCaption
}
30 changes: 30 additions & 0 deletions search/IndexSanityContent/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export type ImageWithAlt = {
_type: 'imageWithAlt'
alt: string
isDecorative?: boolean
asset: {
_ref: string
_type: 'reference'
}
crop?: {
_type: 'sanity.imageCrop'
bottom: number
left: number
right: number
top: number
}
hotspot?: {
_type: 'sanity.imageHotspot'
height: number
width: number
x: number
y: number
}
}

export type ImageWithAltAndCaption = {
_type: 'imageWithAltAndCaption'
attribution?: string
caption?: string
image: ImageWithAlt
}
1 change: 1 addition & 0 deletions search/IndexSanityContent/localNews/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const query = /* groq */ `*[_type == "localNews" && lang == $lang && !(_i
title,
"text": pt::text(content)
},
heroImage,
"docToClear": _id match $id
}
`
Expand Down
3 changes: 2 additions & 1 deletion search/IndexSanityContent/magazine/mapper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { pipe } from 'fp-ts/lib/function'
import * as A from 'fp-ts/lib/Array'
import * as O from 'fp-ts/lib/Option'
import { ImageWithAlt, MagazineArticle } from './sanity'
import { MagazineArticle } from './sanity'
import { AccordionIndex, MagazineIndex, TextBlockIndex } from '../../common'
import { mappedAccordions, mappedTextBlocks } from '../common/mappers'
import { ImageWithAlt } from '../common/types'

const getHeroImage = (article: MagazineArticle): ImageWithAlt | null => {
if (article?.heroFigure?.image?.asset) {
Expand Down
32 changes: 1 addition & 31 deletions search/IndexSanityContent/magazine/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SanityClient } from '@sanity/client'
import { Language } from '../../common'
import { MappableAccordionType, MappableTextBlockType } from '../common/mappers'
import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers'
import { ImageWithAlt, ImageWithAltAndCaption } from '../common/types'

export enum HeroTypes {
DEFAULT = 'default',
Expand Down Expand Up @@ -62,37 +63,6 @@ const getQueryParams = (language: Language, id: string) => ({
id: id,
})

export type ImageWithAlt = {
_type: 'imageWithAlt'
alt: string
isDecorative?: boolean
asset: {
_ref: string
_type: 'reference'
}
crop?: {
_type: 'sanity.imageCrop'
bottom: number
left: number
right: number
top: number
}
hotspot?: {
_type: 'sanity.imageHotspot'
height: number
width: number
x: number
y: number
}
}

export type ImageWithAltAndCaption = {
_type: 'imageWithAltAndCaption'
attribution?: string
caption?: string
image: ImageWithAlt
}

export type MagazineArticle = {
slug: string
title: string
Expand Down
4 changes: 3 additions & 1 deletion search/IndexSanityContent/news/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { NewsArticle } from './sanity'

type MapDataType = (article: NewsArticle) => NewsIndex[]
export const mapData: MapDataType = (article) => {
const { publishDateTime, topicTags, countryTags, title, ingress, slug, factboxes } = article
const { publishDateTime, topicTags, countryTags, title, ingress, slug, factboxes, heroImage } = article
// Hu hei hvor det går
const year = publishDateTime ? new Date(publishDateTime).getFullYear() : ''
return pipe(
Expand All @@ -24,6 +24,7 @@ export const mapData: MapDataType = (article) => {
topicTags,
countryTags,
year,
heroImage,
} as NewsIndex),
),
A.concat(
Expand All @@ -40,6 +41,7 @@ export const mapData: MapDataType = (article) => {
topicTags,
countryTags,
year,
heroImage,
} as NewsIndex),
),
),
Expand Down
1 change: 1 addition & 0 deletions search/IndexSanityContent/news/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const query = /* groq */ `*[_type == "news" && lang == $lang && !(_id in
title,
"text": pt::text(content)
},
heroImage,
"docToClear": _id match $id
}
`
Expand Down
1 change: 1 addition & 0 deletions search/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type NewsIndex = {
countryTags: string[]
thumbnailUrl: string
localNewsTag: string
heroImage: object
}

export type MagazineIndex = {
Expand Down
14 changes: 7 additions & 7 deletions web/common/helpers/getPaths.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { groq } from 'next-sanity'
import { getNameFromLocale } from '../../lib/localization'
import { publishDateTimeQuery } from '../../lib/queries/common/publishDateTime'
import { sanityClient } from '../../lib/sanity.server'
import { getClient } from '../../lib/sanity.server'
import { noDrafts, sameLang } from './../../lib/queries/common/langAndDrafts'

// These URLs uses SSR and thus should not be static rendered
Expand All @@ -14,7 +14,7 @@ const getTopicRoutesForLocale = async (locale: string) => {
const lang = getNameFromLocale(locale)
// Empty array as fallback for satelittes
const blacklist = topicSlugBlackList[lang as keyof typeof topicSlugBlackList] || []
const data: { slug: string; _updatedAt: string }[] = await sanityClient.fetch(
const data: { slug: string; _updatedAt: string }[] = await getClient(false).fetch(
groq`*[_type match "route_" + $lang + "*" && (!(slug.current in $blacklist)) && defined(slug.current) && !(_id in path("drafts.**"))][] {
_updatedAt,
"slug": slug.current,
Expand All @@ -30,7 +30,7 @@ const getTopicRoutesForLocaleToStaticallyBuild = async (locale: string) => {
const lang = getNameFromLocale(locale)
// Empty array as fallback for satelittes
const blacklist = topicSlugBlackList[lang as keyof typeof topicSlugBlackList] || []
const data: { slug: string; _updatedAt: string }[] = await sanityClient.fetch(
const data: { slug: string; _updatedAt: string }[] = await getClient(false).fetch(
groq`*[_type match "route_" + $lang + "*" && (!(slug.current in $blacklist)) && includeInBuild && defined(slug.current) && !(_id in path("drafts.**"))][] {
_updatedAt,
"slug": slug.current,
Expand All @@ -45,7 +45,7 @@ const getTopicRoutesForLocaleToStaticallyBuild = async (locale: string) => {

const getDocumentsForLocale = async (type: 'news' | 'localNews' | 'magazine', locale: string) => {
const lang = getNameFromLocale(locale)
const data: { slug: string; _updatedAt: string }[] = await sanityClient.fetch(
const data: { slug: string; _updatedAt: string }[] = await getClient(false).fetch(
groq`*[_type == $type && defined(slug.current) && ${sameLang} && ${noDrafts}][] {
_updatedAt,
"slug": slug.current,
Expand All @@ -62,7 +62,7 @@ const getDocumentsForLocale = async (type: 'news' | 'localNews' | 'magazine', lo
// Only include drafts if preview mode is enabled
export const getDocumentBySlug = async (slug: string, isPreview = false) => {
const draft = isPreview ? `` : /* groq */ `&& ${noDrafts}`
const data: { slug: string; _updatedAt: string }[] = await sanityClient.fetch(
const data: { slug: string; _updatedAt: string }[] = await getClient(false).fetch(
groq`*[defined(slug.current) && slug.current == $slug ${draft}][0] {
_updatedAt,
"slug": slug.current,
Expand Down Expand Up @@ -148,7 +148,7 @@ export const getLocalNewsPaths = async (locales: string[]): Promise<PathType[]>
export const getNewsroomPaths = async (): Promise<PathType[]> => {
// Use last published news as updatedAt field for newsroom
const getUpdatedAt = async (lang: 'en_GB' | 'nb_NO'): Promise<{ _updatedAt: string }> =>
await sanityClient.fetch(
await getClient(false).fetch(
groq`*[_type == 'news' && ${sameLang} && ${noDrafts}] | order(${publishDateTimeQuery} desc)[0] {
_updatedAt,
}`,
Expand Down Expand Up @@ -177,7 +177,7 @@ export const getNewsroomPaths = async (): Promise<PathType[]> => {
export const getMagazineIndexPaths = async (): Promise<PathType[]> => {
// Use last published news as updatedAt field for newsroom
const getUpdatedAt = async (lang: 'en_GB' | 'nb_NO'): Promise<{ _updatedAt: string }> =>
await sanityClient.fetch(
await getClient(false).fetch(
groq`*[_type == 'magazine' && ${sameLang} && ${noDrafts}] | order(_createdAt desc)[0] {
_updatedAt,
}`,
Expand Down
Loading

0 comments on commit 4f32e2e

Please sign in to comment.