|
1 | 1 | import type { Context, Page } from '@/types' |
2 | 2 | import type { PageTransformer } from './types' |
| 3 | +import { renderContent } from '@/content-render/index' |
| 4 | +import { loadTemplate } from '@/article-api/lib/load-template' |
3 | 5 | import { stripHtmlCommentsAndNormalizeWhitespace } from '@/article-api/lib/strip-html-comments' |
4 | 6 |
|
5 | 7 | /** |
6 | 8 | * Transformer for CodeQL CLI reference pages. |
7 | | - * Renders autogenerated CodeQL CLI documentation pages as markdown. |
| 9 | + * Renders autogenerated CodeQL CLI documentation pages as markdown using a Liquid template. |
8 | 10 | * Sets `markdownRequested` to true in the context to ensure the page is rendered as markdown, |
9 | 11 | * bypassing the default article type check. |
10 | 12 | */ |
11 | 13 | export class CodeQLCliTransformer implements PageTransformer { |
| 14 | + templateName = 'codeql-cli-page.template.md' |
| 15 | + |
12 | 16 | canTransform(page: Page): boolean { |
13 | 17 | return page.autogenerated === 'codeql-cli' |
14 | 18 | } |
15 | 19 |
|
16 | 20 | async transform(page: Page, _pathname: string, context: Context): Promise<string> { |
17 | 21 | // CodeQL CLI pages are fully generated markdown files in the repo. |
18 | | - // We render them with markdownRequested=true to get the markdown output, |
19 | | - // similar to how regular articles are rendered but through the transformer pattern. |
| 22 | + // We render them with markdownRequested=true to get the markdown output. |
20 | 23 | context.markdownRequested = true |
21 | 24 | const content = await page.render(context) |
22 | 25 |
|
23 | 26 | const intro = page.intro ? await page.renderProp('intro', context, { textOnly: true }) : '' |
24 | 27 |
|
25 | | - const result = `# ${page.title}\n\n${intro}\n\n${content}` |
| 28 | + // Prepare template data |
| 29 | + const templateData: Record<string, unknown> = { |
| 30 | + page: { |
| 31 | + title: page.title, |
| 32 | + intro, |
| 33 | + }, |
| 34 | + content, |
| 35 | + } |
| 36 | + |
| 37 | + // Load and render template |
| 38 | + const templateContent = loadTemplate(this.templateName) |
| 39 | + |
| 40 | + const result = await renderContent(templateContent, { |
| 41 | + ...context, |
| 42 | + ...templateData, |
| 43 | + markdownRequested: true, |
| 44 | + }) |
26 | 45 |
|
27 | 46 | // Strip HTML comments (e.g., markdownlint-disable comments) from the output |
28 | 47 | return stripHtmlCommentsAndNormalizeWhitespace(result) |
|
0 commit comments