|
| 1 | +import { Liquid } from 'liquidjs' |
| 2 | +import GithubSlugger from 'github-slugger' |
| 3 | +// Copilot: When converting data.js to TypeScript, remove the 'as any' assertion for anyData below |
| 4 | +import Data from './data' |
| 5 | +import Octicon from './octicon' |
| 6 | +// Copilot: When converting ifversion.js to TypeScript, remove the 'as any' assertion for anyIfversion below |
| 7 | +import Ifversion from './ifversion' |
| 8 | +// Copilot: When converting tool.js to TypeScript, remove the 'as any' assertion for anyTool below |
| 9 | +import { Tool, tags as toolTags } from './tool' |
| 10 | +import { Spotlight, tags as spotlightTags } from './spotlight' |
| 11 | +import { Prompt } from './prompt' |
| 12 | +import IndentedDataReference from './indented-data-reference' |
| 13 | + |
| 14 | +// Type assertions for .js files without type definitions |
| 15 | +// Copilot: Remove these assertions when the corresponding .js files are converted to TypeScript |
| 16 | +const anyData = Data as any |
| 17 | +const anyIfversion = Ifversion as any |
| 18 | +const anyTool = Tool as any |
| 19 | +const anySpotlight = Spotlight as any |
| 20 | +const anyPrompt = Prompt as any |
| 21 | +const anyIndentedDataReference = IndentedDataReference as any |
| 22 | + |
| 23 | +export const engine = new Liquid({ |
| 24 | + extname: '.html', |
| 25 | + dynamicPartials: false, |
| 26 | +}) |
| 27 | + |
| 28 | +engine.registerTag('indented_data_reference', anyIndentedDataReference) |
| 29 | +engine.registerTag('data', anyData) |
| 30 | +engine.registerTag('octicon', Octicon) |
| 31 | +engine.registerTag('ifversion', anyIfversion) |
| 32 | + |
| 33 | +for (const tag of toolTags) { |
| 34 | + engine.registerTag(tag, anyTool) |
| 35 | +} |
| 36 | + |
| 37 | +for (const tag in spotlightTags) { |
| 38 | + engine.registerTag(tag, anySpotlight) |
| 39 | +} |
| 40 | + |
| 41 | +engine.registerTag('prompt', anyPrompt) |
| 42 | + |
| 43 | +/** |
| 44 | + * Like the `size` filter, but specifically for |
| 45 | + * getting the number of keys in an object |
| 46 | + */ |
| 47 | +engine.registerFilter('obj_size', (input: Record<string, unknown> | null | undefined): number => { |
| 48 | + if (!input) return 0 |
| 49 | + return Object.keys(input).length |
| 50 | +}) |
| 51 | + |
| 52 | +/** |
| 53 | + * Returns the version number of a GHES version string |
| 54 | + * ex: enterprise-server@2.22 => 2.22 |
| 55 | + */ |
| 56 | +engine.registerFilter('version_num', (input: string): string => { |
| 57 | + return input.split('@')[1] |
| 58 | +}) |
| 59 | + |
| 60 | +/** |
| 61 | + * Convert the input to a slug |
| 62 | + */ |
| 63 | +engine.registerFilter('slugify', (input: string): string => { |
| 64 | + const slugger = new GithubSlugger() |
| 65 | + return slugger.slug(input) |
| 66 | +}) |
0 commit comments