Emit contentType field as content_type in page events (#58325)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: felicitymay <1877141+felicitymay@users.noreply.github.com>
This commit is contained in:
@@ -110,6 +110,7 @@ export function sendEvent<T extends EventType>({
|
|||||||
path_article: getMetaContent('path-article'),
|
path_article: getMetaContent('path-article'),
|
||||||
page_document_type: getMetaContent('page-document-type'),
|
page_document_type: getMetaContent('page-document-type'),
|
||||||
page_type: getMetaContent('page-type'),
|
page_type: getMetaContent('page-type'),
|
||||||
|
content_type: getMetaContent('page-content-type'),
|
||||||
status: Number(getMetaContent('status') || 0),
|
status: Number(getMetaContent('status') || 0),
|
||||||
is_logged_in: isLoggedIn(),
|
is_logged_in: isLoggedIn(),
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { languageKeys } from '@/languages/lib/languages-server'
|
|||||||
import { allVersionKeys } from '@/versions/lib/all-versions'
|
import { allVersionKeys } from '@/versions/lib/all-versions'
|
||||||
import { productIds } from '@/products/lib/all-products'
|
import { productIds } from '@/products/lib/all-products'
|
||||||
import { allTools } from '@/tools/lib/all-tools'
|
import { allTools } from '@/tools/lib/all-tools'
|
||||||
|
import { contentTypesEnum } from '@/frame/lib/frontmatter'
|
||||||
|
|
||||||
const versionPattern = '^\\d+(\\.\\d+)?(\\.\\d+)?$'
|
const versionPattern = '^\\d+(\\.\\d+)?(\\.\\d+)?$'
|
||||||
|
|
||||||
@@ -100,6 +101,11 @@ const context = {
|
|||||||
description: 'Optional page type from the content frontmatter.',
|
description: 'Optional page type from the content frontmatter.',
|
||||||
enum: ['overview', 'quick_start', 'tutorial', 'how_to', 'reference', 'rai'], // frontmatter.ts
|
enum: ['overview', 'quick_start', 'tutorial', 'how_to', 'reference', 'rai'], // frontmatter.ts
|
||||||
},
|
},
|
||||||
|
content_type: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Optional content type from the content frontmatter (EDI content models).',
|
||||||
|
enum: contentTypesEnum,
|
||||||
|
},
|
||||||
status: {
|
status: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The HTTP response status code of the main page HTML.',
|
description: 'The HTTP response status code of the main page HTML.',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { describe, expect, test, vi } from 'vitest'
|
import { describe, expect, test, vi } from 'vitest'
|
||||||
|
|
||||||
import { post } from '@/tests/helpers/e2etest'
|
import { post } from '@/tests/helpers/e2etest'
|
||||||
|
import { contentTypesEnum } from '@/frame/lib/frontmatter'
|
||||||
|
|
||||||
describe('POST /events', () => {
|
describe('POST /events', () => {
|
||||||
vi.setConfig({ testTimeout: 60 * 1000 })
|
vi.setConfig({ testTimeout: 60 * 1000 })
|
||||||
@@ -163,4 +164,28 @@ describe('POST /events', () => {
|
|||||||
})
|
})
|
||||||
expect(statusCode).toBe(400)
|
expect(statusCode).toBe(400)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should accept content_type field', async () => {
|
||||||
|
const { statusCode } = await checkEvent({
|
||||||
|
...pageExample,
|
||||||
|
context: {
|
||||||
|
...pageExample.context,
|
||||||
|
content_type: 'how-tos',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(statusCode).toBe(200)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should accept valid content_type values from EDI content models', async () => {
|
||||||
|
for (const contentType of contentTypesEnum) {
|
||||||
|
const { statusCode } = await checkEvent({
|
||||||
|
...pageExample,
|
||||||
|
context: {
|
||||||
|
...pageExample.context,
|
||||||
|
content_type: contentType,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(statusCode).toBe(200)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export type EventProps = {
|
|||||||
path_article: string
|
path_article: string
|
||||||
page_document_type: string
|
page_document_type: string
|
||||||
page_type: string
|
page_type: string
|
||||||
|
content_type: string
|
||||||
status: number
|
status: number
|
||||||
is_logged_in: boolean
|
is_logged_in: boolean
|
||||||
dotcom_user: string
|
dotcom_user: string
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ export const DefaultLayout = (props: Props) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{page.type && <meta name="page-type" content={page.type} />}
|
{page.type && <meta name="page-type" content={page.type} />}
|
||||||
|
{page.contentType && <meta name="page-content-type" content={page.contentType} />}
|
||||||
{page.documentType && <meta name="page-document-type" content={page.documentType} />}
|
{page.documentType && <meta name="page-document-type" content={page.documentType} />}
|
||||||
{status && <meta name="status" content={status.toString()} />}
|
{status && <meta name="status" content={status.toString()} />}
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export type MainContextT = {
|
|||||||
page: {
|
page: {
|
||||||
documentType: string
|
documentType: string
|
||||||
type?: string
|
type?: string
|
||||||
|
contentType?: string
|
||||||
topics: Array<string>
|
topics: Array<string>
|
||||||
title: string
|
title: string
|
||||||
fullTitle?: string
|
fullTitle?: string
|
||||||
@@ -217,6 +218,7 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
|
|||||||
(page && {
|
(page && {
|
||||||
documentType,
|
documentType,
|
||||||
type: req.context.page.type || null,
|
type: req.context.page.type || null,
|
||||||
|
contentType: req.context.page.contentType || null,
|
||||||
title: req.context.page.title,
|
title: req.context.page.title,
|
||||||
fullTitle: req.context.page.fullTitle || null,
|
fullTitle: req.context.page.fullTitle || null,
|
||||||
topics: req.context.page.topics || [],
|
topics: req.context.page.topics || [],
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export type PageFrontmatter = {
|
|||||||
featuredLinks?: FeaturedLinks
|
featuredLinks?: FeaturedLinks
|
||||||
changelog?: ChangeLog
|
changelog?: ChangeLog
|
||||||
type?: string
|
type?: string
|
||||||
|
contentType?: string
|
||||||
topics?: string[]
|
topics?: string[]
|
||||||
includeGuides?: string[]
|
includeGuides?: string[]
|
||||||
learningTracks?: string[]
|
learningTracks?: string[]
|
||||||
@@ -380,6 +381,8 @@ export type Page = {
|
|||||||
complexity?: string[]
|
complexity?: string[]
|
||||||
industry?: string[]
|
industry?: string[]
|
||||||
sidebarLink?: SidebarLink
|
sidebarLink?: SidebarLink
|
||||||
|
type?: string
|
||||||
|
contentType?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SidebarLink = {
|
export type SidebarLink = {
|
||||||
|
|||||||
Reference in New Issue
Block a user