-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fd5669
commit bd4d1ae
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Html } from 'mdast'; | ||
import { SKIP } from 'unist-util-visit'; | ||
|
||
import type { MacroFunction, MacroNode } from '../types.ts'; | ||
import { wrappedStringSchema } from '../validation.ts'; | ||
|
||
function parseArguments(value: string[]): [string, string | undefined] { | ||
if (value.length === 0 || !value[0]) { | ||
throw new Error('No arguments provided'); | ||
} | ||
return [ | ||
wrappedStringSchema.parse(value[0]), | ||
value[1] ? wrappedStringSchema.parse(value[1]) : undefined, | ||
]; | ||
} | ||
|
||
function macro(node: MacroNode): Html { | ||
const targetLocale = process.env.TARGET_LOCALE; | ||
let arguments_ = parseArguments(node.parameters); | ||
let string_ = arguments_[1] || arguments_[0]; | ||
|
||
const basePath = `/${targetLocale}/docs/Glossary/`; | ||
const subPath = arguments_[0].replaceAll(/\s+/g, '_'); | ||
|
||
return { | ||
type: 'html', | ||
value: `<a href="${basePath + subPath}">${string_}</a>`, | ||
}; | ||
} | ||
|
||
const glossary: MacroFunction = (node, index, parent) => { | ||
const replacement = macro(node); | ||
parent.children[index] = replacement; | ||
return [SKIP, index]; | ||
}; | ||
|
||
export default glossary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters