Skip to content

Commit 14d3198

Browse files
Copilotfelicitymay
andauthored
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>
1 parent 35616b0 commit 14d3198

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

src/events/components/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export function sendEvent<T extends EventType>({
110110
path_article: getMetaContent('path-article'),
111111
page_document_type: getMetaContent('page-document-type'),
112112
page_type: getMetaContent('page-type'),
113+
content_type: getMetaContent('page-content-type'),
113114
status: Number(getMetaContent('status') || 0),
114115
is_logged_in: isLoggedIn(),
115116

src/events/lib/schema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { languageKeys } from '@/languages/lib/languages-server'
22
import { allVersionKeys } from '@/versions/lib/all-versions'
33
import { productIds } from '@/products/lib/all-products'
44
import { allTools } from '@/tools/lib/all-tools'
5+
import { contentTypesEnum } from '@/frame/lib/frontmatter'
56

67
const versionPattern = '^\\d+(\\.\\d+)?(\\.\\d+)?$'
78

@@ -100,6 +101,11 @@ const context = {
100101
description: 'Optional page type from the content frontmatter.',
101102
enum: ['overview', 'quick_start', 'tutorial', 'how_to', 'reference', 'rai'], // frontmatter.ts
102103
},
104+
content_type: {
105+
type: 'string',
106+
description: 'Optional content type from the content frontmatter (EDI content models).',
107+
enum: contentTypesEnum,
108+
},
103109
status: {
104110
type: 'number',
105111
description: 'The HTTP response status code of the main page HTML.',

src/events/tests/middleware.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, test, vi } from 'vitest'
22

33
import { post } from '@/tests/helpers/e2etest'
4+
import { contentTypesEnum } from '@/frame/lib/frontmatter'
45

56
describe('POST /events', () => {
67
vi.setConfig({ testTimeout: 60 * 1000 })
@@ -163,4 +164,28 @@ describe('POST /events', () => {
163164
})
164165
expect(statusCode).toBe(400)
165166
})
167+
168+
test('should accept content_type field', async () => {
169+
const { statusCode } = await checkEvent({
170+
...pageExample,
171+
context: {
172+
...pageExample.context,
173+
content_type: 'how-tos',
174+
},
175+
})
176+
expect(statusCode).toBe(200)
177+
})
178+
179+
test('should accept valid content_type values from EDI content models', async () => {
180+
for (const contentType of contentTypesEnum) {
181+
const { statusCode } = await checkEvent({
182+
...pageExample,
183+
context: {
184+
...pageExample.context,
185+
content_type: contentType,
186+
},
187+
})
188+
expect(statusCode).toBe(200)
189+
}
190+
})
166191
})

src/events/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type EventProps = {
3636
path_article: string
3737
page_document_type: string
3838
page_type: string
39+
content_type: string
3940
status: number
4041
is_logged_in: boolean
4142
dotcom_user: string

src/frame/components/DefaultLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const DefaultLayout = (props: Props) => {
119119
/>
120120
)}
121121
{page.type && <meta name="page-type" content={page.type} />}
122+
{page.contentType && <meta name="page-content-type" content={page.contentType} />}
122123
{page.documentType && <meta name="page-document-type" content={page.documentType} />}
123124
{status && <meta name="status" content={status.toString()} />}
124125

src/frame/components/context/MainContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export type MainContextT = {
118118
page: {
119119
documentType: string
120120
type?: string
121+
contentType?: string
121122
topics: Array<string>
122123
title: string
123124
fullTitle?: string
@@ -217,6 +218,7 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
217218
(page && {
218219
documentType,
219220
type: req.context.page.type || null,
221+
contentType: req.context.page.contentType || null,
220222
title: req.context.page.title,
221223
fullTitle: req.context.page.fullTitle || null,
222224
topics: req.context.page.topics || [],

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type PageFrontmatter = {
5151
featuredLinks?: FeaturedLinks
5252
changelog?: ChangeLog
5353
type?: string
54+
contentType?: string
5455
topics?: string[]
5556
includeGuides?: string[]
5657
learningTracks?: string[]
@@ -380,6 +381,8 @@ export type Page = {
380381
complexity?: string[]
381382
industry?: string[]
382383
sidebarLink?: SidebarLink
384+
type?: string
385+
contentType?: string
383386
}
384387

385388
export type SidebarLink = {

0 commit comments

Comments
 (0)