Skip to content

Commit 492685b

Browse files
authored
Add sidebarLink frontmatter property for custom sidebar links (#56238)
1 parent d6ae404 commit 492685b

File tree

17 files changed

+231
-8
lines changed

17 files changed

+231
-8
lines changed

content/copilot/tutorials/copilot-chat-cookbook/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ versions:
1010
topics:
1111
- Copilot
1212
layout: category-landing
13+
sidebarLink:
14+
text: All prompts
15+
href: /copilot/copilot-chat-cookbook
1316
spotlight:
1417
- article: /testing-code/generate-unit-tests
1518
image: /assets/images/copilot-landing/generating_unit_tests.png

src/article-api/middleware/article-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Response } from 'express'
22

33
import { Context } from '@/types'
4-
import { ExtendedRequestWithPageInfo } from '../types'
4+
import { ExtendedRequestWithPageInfo } from '@/article-api/types'
55
import contextualize from '@/frame/middleware/context/context'
66

77
export async function getArticleBody(req: ExtendedRequestWithPageInfo) {

src/content-linter/tests/unit/frontmatter-schema.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,52 @@ describe(frontmatterSchema.names.join(' - '), () => {
4848
expect(errors[0].lineNumber).toBe(1)
4949
expect(errors[0].errorRange).toEqual(null)
5050
})
51+
52+
test('sidebarLink with valid object properties passes', async () => {
53+
const markdown = [
54+
'---',
55+
'title: Title',
56+
'versions:',
57+
" fpt: '*'",
58+
'sidebarLink:',
59+
' text: "All prompts"',
60+
' href: "/copilot/copilot-chat-cookbook"',
61+
'---',
62+
].join('\n')
63+
const result = await runRule(frontmatterSchema, { strings: { markdown }, ...fmOptions })
64+
const errors = result.markdown
65+
expect(errors.length).toBe(0)
66+
})
67+
68+
test('sidebarLink with missing text property fails', async () => {
69+
const markdown = [
70+
'---',
71+
'title: Title',
72+
'versions:',
73+
" fpt: '*'",
74+
'sidebarLink:',
75+
' href: "/copilot/copilot-chat-cookbook"',
76+
'---',
77+
].join('\n')
78+
const result = await runRule(frontmatterSchema, { strings: { markdown }, ...fmOptions })
79+
const errors = result.markdown
80+
expect(errors.length).toBe(1)
81+
expect(errors[0].lineNumber).toBe(5)
82+
})
83+
84+
test('sidebarLink with missing href property fails', async () => {
85+
const markdown = [
86+
'---',
87+
'title: Title',
88+
'versions:',
89+
" fpt: '*'",
90+
'sidebarLink:',
91+
' text: "All prompts"',
92+
'---',
93+
].join('\n')
94+
const result = await runRule(frontmatterSchema, { strings: { markdown }, ...fmOptions })
95+
const errors = result.markdown
96+
expect(errors.length).toBe(1)
97+
expect(errors[0].lineNumber).toBe(5)
98+
})
5199
})

src/fixtures/fixtures/content/get-started/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ featuredLinks:
1919
children:
2020
- /start-your-journey
2121
- /foo
22+
- /sidebar-test
2223
- /video-transcripts
2324
- /minitocs
2425
- /liquid
@@ -31,5 +32,5 @@ communityRedirect:
3132
name: Provide HubGit Feedback
3233
href: 'https://hubgit.com/orgs/community/discussions/categories/get-started'
3334
product_video: 'https://www.yourube.com/abc123'
34-
product_video_transcript: '/get-started/video-transcripts/transcript--my-awesome-video'
35+
product_video_transcript: '/video-transcripts/transcript--my-awesome-video'
3536
---
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Sidebar Test Page
3+
intro: 'Test page for sidebar custom link functionality'
4+
versions:
5+
fpt: '*'
6+
ghes: '*'
7+
ghec: '*'
8+
sidebarLink:
9+
text: All sidebar test items
10+
href: /get-started/sidebar-test
11+
children:
12+
- /test-child
13+
---
14+
15+
This is a test page for the sidebar custom link functionality.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Test Child Page
3+
intro: 'Child page for testing sidebar functionality'
4+
versions:
5+
fpt: '*'
6+
ghes: '*'
7+
ghec: '*'
8+
---
9+
10+
This is a test child page under the sidebar test section.

src/fixtures/fixtures/content/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ children:
3232
- actions
3333
- rest
3434
- webhooks
35+
- video-transcripts
3536
# - account-and-profile
3637
# - authentication
3738
# - repositories
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Video transcripts
3+
intro: 'Collection of video transcripts for accessibility and reference.'
4+
versions:
5+
fpt: '*'
6+
ghes: '*'
7+
ghec: '*'
8+
children:
9+
- /transcript--my-awesome-video
10+
---
11+
12+
This section contains transcripts for videos used throughout the documentation.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Transcript - My awesome video
3+
product_video: 'https://www.yourube.com/abc123'
4+
versions:
5+
fpt: '*'
6+
ghes: '*'
7+
ghec: '*'
8+
---
9+
10+
This is a transcript

src/fixtures/tests/playwright-rendering.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,19 @@ test('navigate with side bar into article inside a subcategory inside a category
324324
await expect(page).toHaveURL(/actions\/category\/subcategory\/article/)
325325
})
326326

327+
test('sidebar custom link functionality works', async ({ page }) => {
328+
// Test that sidebar functionality is not broken by custom links feature
329+
await page.goto('/get-started')
330+
331+
await expect(page).toHaveTitle(/Getting started with HubGit/)
332+
333+
// Verify that regular sidebar navigation still works by clicking on known sections
334+
await page.getByTestId('product-sidebar').getByText('Start your journey').click()
335+
await page.getByTestId('product-sidebar').getByText('Hello World').click()
336+
await expect(page).toHaveURL(/\/en\/get-started\/start-your-journey\/hello-world/)
337+
await expect(page).toHaveTitle(/Hello World - GitHub Docs/)
338+
})
339+
327340
test.describe('hover cards', () => {
328341
test('hover over link', async ({ page }) => {
329342
await page.goto('/pages/quickstart')

0 commit comments

Comments
 (0)