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'),
|
||||
page_document_type: getMetaContent('page-document-type'),
|
||||
page_type: getMetaContent('page-type'),
|
||||
content_type: getMetaContent('page-content-type'),
|
||||
status: Number(getMetaContent('status') || 0),
|
||||
is_logged_in: isLoggedIn(),
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { languageKeys } from '@/languages/lib/languages-server'
|
||||
import { allVersionKeys } from '@/versions/lib/all-versions'
|
||||
import { productIds } from '@/products/lib/all-products'
|
||||
import { allTools } from '@/tools/lib/all-tools'
|
||||
import { contentTypesEnum } from '@/frame/lib/frontmatter'
|
||||
|
||||
const versionPattern = '^\\d+(\\.\\d+)?(\\.\\d+)?$'
|
||||
|
||||
@@ -100,6 +101,11 @@ const context = {
|
||||
description: 'Optional page type from the content frontmatter.',
|
||||
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: {
|
||||
type: 'number',
|
||||
description: 'The HTTP response status code of the main page HTML.',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
|
||||
import { post } from '@/tests/helpers/e2etest'
|
||||
import { contentTypesEnum } from '@/frame/lib/frontmatter'
|
||||
|
||||
describe('POST /events', () => {
|
||||
vi.setConfig({ testTimeout: 60 * 1000 })
|
||||
@@ -163,4 +164,28 @@ describe('POST /events', () => {
|
||||
})
|
||||
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
|
||||
page_document_type: string
|
||||
page_type: string
|
||||
content_type: string
|
||||
status: number
|
||||
is_logged_in: boolean
|
||||
dotcom_user: string
|
||||
|
||||
@@ -119,6 +119,7 @@ export const DefaultLayout = (props: Props) => {
|
||||
/>
|
||||
)}
|
||||
{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} />}
|
||||
{status && <meta name="status" content={status.toString()} />}
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ export type MainContextT = {
|
||||
page: {
|
||||
documentType: string
|
||||
type?: string
|
||||
contentType?: string
|
||||
topics: Array<string>
|
||||
title: string
|
||||
fullTitle?: string
|
||||
@@ -217,6 +218,7 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
|
||||
(page && {
|
||||
documentType,
|
||||
type: req.context.page.type || null,
|
||||
contentType: req.context.page.contentType || null,
|
||||
title: req.context.page.title,
|
||||
fullTitle: req.context.page.fullTitle || null,
|
||||
topics: req.context.page.topics || [],
|
||||
|
||||
@@ -51,6 +51,7 @@ export type PageFrontmatter = {
|
||||
featuredLinks?: FeaturedLinks
|
||||
changelog?: ChangeLog
|
||||
type?: string
|
||||
contentType?: string
|
||||
topics?: string[]
|
||||
includeGuides?: string[]
|
||||
learningTracks?: string[]
|
||||
@@ -380,6 +381,8 @@ export type Page = {
|
||||
complexity?: string[]
|
||||
industry?: string[]
|
||||
sidebarLink?: SidebarLink
|
||||
type?: string
|
||||
contentType?: string
|
||||
}
|
||||
|
||||
export type SidebarLink = {
|
||||
|
||||
Reference in New Issue
Block a user