website/docs: Update Docusaurus config. Prep for version picker. (#14401)
* website/docs: Clean up config. Add types. * website/docs: Format MDX. * website: Fix build warnings. Lint badges frontmatter.
This commit is contained in:
47
website/remark/preview-directive.mjs
Normal file
47
website/remark/preview-directive.mjs
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file Remark plugin to transform `ak-preview` directives into preview badges.
|
||||
*
|
||||
* @import { Root } from "mdast";
|
||||
*/
|
||||
import { h } from "hastscript";
|
||||
import { SKIP, visit } from "unist-util-visit";
|
||||
|
||||
/**
|
||||
* MDAST plugin to transform `ak-preview` directives into preview badges.
|
||||
*/
|
||||
function remarkPreviewDirective() {
|
||||
/**
|
||||
* @param {Root} tree The MDAST tree to transform.
|
||||
*/
|
||||
return function (tree) {
|
||||
visit(tree, "textDirective", function (node) {
|
||||
if (node.name !== "ak-preview") return SKIP;
|
||||
|
||||
const data = node.data || (node.data = {});
|
||||
|
||||
const hast = h("span", {
|
||||
...node.attributes,
|
||||
"className": "badge badge--preview",
|
||||
"title": `This feature is in preview and may change in the future.`,
|
||||
"aria-description": "Preview badge",
|
||||
"role": "img",
|
||||
});
|
||||
|
||||
data.hName = hast.tagName;
|
||||
data.hProperties = hast.properties;
|
||||
|
||||
data.hChildren = [
|
||||
{
|
||||
type: "text",
|
||||
value: "Preview",
|
||||
},
|
||||
];
|
||||
|
||||
node.children = [];
|
||||
|
||||
return SKIP;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default remarkPreviewDirective;
|
Reference in New Issue
Block a user