( builder: CodeBuilder, plugins: PluginCodegenResult[], depth = 1, )
| 13 | }; |
| 14 | |
| 15 | export function addCategories( |
| 16 | builder: CodeBuilder, |
| 17 | plugins: PluginCodegenResult[], |
| 18 | depth = 1, |
| 19 | ): void { |
| 20 | const categories = mergeCategoriesBySlug( |
| 21 | plugins.flatMap(p => p.categories ?? []).map(toMergedCategory), |
| 22 | ); |
| 23 | if (categories.length === 0) { |
| 24 | return; |
| 25 | } |
| 26 | builder.addLine('categories: [', depth); |
| 27 | categories.forEach( |
| 28 | ({ slug, title, description, docsUrl, refs, refsExpressions }) => { |
| 29 | builder.addLine('{', depth + 1); |
| 30 | builder.addLine(`slug: '${slug}',`, depth + 2); |
| 31 | builder.addLine(`title: ${singleQuote(title)},`, depth + 2); |
| 32 | if (description) { |
| 33 | builder.addLine(`description: ${singleQuote(description)},`, depth + 2); |
| 34 | } |
| 35 | if (docsUrl) { |
| 36 | builder.addLine(`docsUrl: ${singleQuote(docsUrl)},`, depth + 2); |
| 37 | } |
| 38 | addCategoryRefs(builder, refs, refsExpressions, depth + 2); |
| 39 | builder.addLine('},', depth + 1); |
| 40 | }, |
| 41 | ); |
| 42 | builder.addLine('],', depth); |
| 43 | } |
| 44 | |
| 45 | function toMergedCategory(category: CategoryCodegenConfig): MergedCategory { |
| 46 | return { |
no test coverage detected