Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/article-api/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CategoryLandingTransformer } from './category-landing-transformer'
import { DiscoveryLandingTransformer } from './discovery-landing-transformer'
import { ProductGuidesTransformer } from './product-guides-transformer'
import { ProductLandingTransformer } from './product-landing-transformer'
import { SearchPageTransformer } from './search-page-transformer'

/**
* Global transformer registry
Expand All @@ -40,6 +41,7 @@ transformerRegistry.register(new CategoryLandingTransformer())
transformerRegistry.register(new DiscoveryLandingTransformer())
transformerRegistry.register(new ProductGuidesTransformer())
transformerRegistry.register(new ProductLandingTransformer())
transformerRegistry.register(new SearchPageTransformer())

export { TransformerRegistry } from './types'
export type { PageTransformer } from './types'
28 changes: 28 additions & 0 deletions src/article-api/transformers/search-page-transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Context, Page } from '@/types'
import type { PageTransformer } from './types'

/**
* Transformer for the search page (/en/search).
* This is a special UI-only page with no markdown content.
* Returns minimal markdown with just the title.
*/
export class SearchPageTransformer implements PageTransformer {
templateName = ''

canTransform(page: Page): boolean {
// Only match the search page specifically
return page.relativePath === 'search/index.md'
}

async transform(page: Page, _pathname: string, context: Context): Promise<string> {
const title = await page.renderTitle(context, { unwrap: true })
return `# ${title}

Use the Search API to search programmatically:

\`\`\`
curl "https://docs.github.com/api/search?query=actions&language=en&version=free-pro-team@latest"
\`\`\`
`
}
}
7 changes: 4 additions & 3 deletions src/article-api/transformers/toc-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ interface CategoryPage extends Page {

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

canTransform(page: Page): boolean {
// Transform pages that have children but no layout specified
// These are typically category or subcategory pages
// These are typically category, subcategory, product, or homepage pages
const categoryPage = page as CategoryPage
const validDocTypes = ['category', 'subcategory', 'product', 'homepage']
return (
!page.layout &&
(page.documentType === 'category' || page.documentType === 'subcategory') &&
validDocTypes.includes(page.documentType) &&
!!categoryPage.children &&
categoryPage.children.length > 0
)
Expand Down
Loading