Skip to content

Commit 867535b

Browse files
authored
Article API: Fix 403 errors for homepage, product, and search pages (#59148)
1 parent d57dc8c commit 867535b

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/article-api/transformers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { CategoryLandingTransformer } from './category-landing-transformer'
1616
import { DiscoveryLandingTransformer } from './discovery-landing-transformer'
1717
import { ProductGuidesTransformer } from './product-guides-transformer'
1818
import { ProductLandingTransformer } from './product-landing-transformer'
19+
import { SearchPageTransformer } from './search-page-transformer'
1920

2021
/**
2122
* Global transformer registry
@@ -40,6 +41,7 @@ transformerRegistry.register(new CategoryLandingTransformer())
4041
transformerRegistry.register(new DiscoveryLandingTransformer())
4142
transformerRegistry.register(new ProductGuidesTransformer())
4243
transformerRegistry.register(new ProductLandingTransformer())
44+
transformerRegistry.register(new SearchPageTransformer())
4345

4446
export { TransformerRegistry } from './types'
4547
export type { PageTransformer } from './types'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { Context, Page } from '@/types'
2+
import type { PageTransformer } from './types'
3+
4+
/**
5+
* Transformer for the search page (/en/search).
6+
* This is a special UI-only page with no markdown content.
7+
* Returns minimal markdown with just the title.
8+
*/
9+
export class SearchPageTransformer implements PageTransformer {
10+
templateName = ''
11+
12+
canTransform(page: Page): boolean {
13+
// Only match the search page specifically
14+
return page.relativePath === 'search/index.md'
15+
}
16+
17+
async transform(page: Page, _pathname: string, context: Context): Promise<string> {
18+
const title = await page.renderTitle(context, { unwrap: true })
19+
return `# ${title}
20+
21+
Use the Search API to search programmatically:
22+
23+
\`\`\`
24+
curl "https://docs.github.com/api/search?query=actions&language=en&version=free-pro-team@latest"
25+
\`\`\`
26+
`
27+
}
28+
}

src/article-api/transformers/toc-transformer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ interface CategoryPage extends Page {
1111

1212
/**
1313
* Transformer for table of contents (TOC) landing pages - pages with children but no specific layout.
14-
* These are simple navigation pages (category/subcategory) that list child pages with titles and intros.
14+
* These are simple navigation pages (category/subcategory/product/homepage) that list child pages with titles and intros.
1515
* Corresponds to TocLanding component in the web UI.
1616
*/
1717
export class TocTransformer implements PageTransformer {
1818
templateName = 'landing-page.template.md'
1919

2020
canTransform(page: Page): boolean {
2121
// Transform pages that have children but no layout specified
22-
// These are typically category or subcategory pages
22+
// These are typically category, subcategory, product, or homepage pages
2323
const categoryPage = page as CategoryPage
24+
const validDocTypes = ['category', 'subcategory', 'product', 'homepage']
2425
return (
2526
!page.layout &&
26-
(page.documentType === 'category' || page.documentType === 'subcategory') &&
27+
validDocTypes.includes(page.documentType) &&
2728
!!categoryPage.children &&
2829
categoryPage.children.length > 0
2930
)

0 commit comments

Comments
 (0)