Skip to content

Commit

Permalink
Merge pull request #2875 from statisticsnorway/MIM-1894-improve-pagemap
Browse files Browse the repository at this point in the history
[MIM-1894] Array from mainSubjects in PageMap
  • Loading branch information
Glenruben authored Aug 29, 2024
2 parents e1c13d6 + 8f297a8 commit ec140e7
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/resources/site/pages/default/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,20 +368,24 @@ function prepareStructuredData(metaInfo: MetaInfoData, page: DefaultPage): Artic
description: metaInfo.metaInfoDescription
? metaInfo.metaInfoDescription
: page.x['com-enonic-app-metafields']?.['meta-data']?.seoDescription || undefined,
articleSection: metaInfo.metaInfoMainSubject,
articleSection: metaInfo.metaInfoMainSubjects?.toString(),
keywords: metaInfo.metaInfoSearchKeywords,
}
}

function preparePageMap(metainfo: MetaInfoData, page: DefaultPage): string {
const keywords = metainfo.metaInfoSearchKeywords
? `<Attribute name="keywords" value="[${metainfo.metaInfoSearchKeywords}]"/>`
? `<Attribute name="keywords" value="${metainfo.metaInfoSearchKeywords}"/>`
: ''
const author = page.data.authorItemSet
? `<Attribute name="author" value="${ensureArray(page.data.authorItemSet)[0].name}"/>`
: ''
const category = metainfo.metaInfoMainSubject
? `<Attribute name="category" value="${metainfo.metaInfoMainSubject}"/>`
const category = metainfo.metaInfoMainSubjects
? metainfo.metaInfoMainSubjects
.map((subject) => {
return `<Attribute name="category" value="${subject}"/>`
})
.join('\n')
: ''
const contentType = metainfo.metaInfoSearchContentType
? `<Attribute name="contenttype" value="${metainfo.metaInfoSearchContentType}"/>`
Expand Down Expand Up @@ -421,7 +425,7 @@ function parseMetaInfoData(
let metaInfoSearchKeywords: string | undefined
let metaInfoDescription: string | undefined
let metaInfoSearchPublishFrom: string | undefined = page.publish && page.publish.from
let metaInfoMainSubject: string | undefined
let metaInfoMainSubjects: string[] | undefined
let metaInfoTitle: string | undefined =
page.x['com-enonic-app-metafields']?.['meta-data']?.seoTitle || page.displayName

Expand All @@ -448,8 +452,7 @@ function parseMetaInfoData(
}

if (page.type === `${app.name}:article` || page.type === `${app.name}:statistics`) {
const mainSubjects: string = getSubjectsPage(page, req, language.code as string).join(';')
metaInfoMainSubject = mainSubjects
metaInfoMainSubjects = getSubjectsPage(page, req, language.code as string)
}

if (page.type === `${app.name}:statistics`) {
Expand Down Expand Up @@ -477,7 +480,7 @@ function parseMetaInfoData(
metaInfoSearchKeywords,
metaInfoDescription,
metaInfoSearchPublishFrom,
metaInfoMainSubject,
metaInfoMainSubjects,
metaInfoTitle,
}
}
Expand Down Expand Up @@ -690,7 +693,7 @@ interface MetaInfoData {
metaInfoSearchKeywords: string | undefined
metaInfoDescription: string | undefined
metaInfoSearchPublishFrom: string | undefined
metaInfoMainSubject: string | undefined
metaInfoMainSubjects: string[] | undefined
metaInfoTitle: string | undefined
}

Expand Down

0 comments on commit ec140e7

Please sign in to comment.