feat: add GitHub repo card, admonitions (#77)

* Added remark-directive, unist-util-visit

* Add rehype custom components for Github, Admonitions

* pnpm

* Update pnpm-lock

* Corrected hastscript requierement

* Change ad- prefix so adblocks dont block content
This commit is contained in:
Fabrizio
2024-05-02 01:24:20 -03:00
committed by saicaca
parent 5e4ae01af6
commit e1dae88515
9 changed files with 6696 additions and 4724 deletions

View File

@@ -0,0 +1,26 @@
/// <reference types="mdast" />
import { h } from 'hastscript'
/**
* Creates an admonition component.
*
* @param {Object} properties - The properties of the component.
* @param {string} [properties.title] - An optional title.
* @param {('tip'|'note'|'important'|'caution'|'warning')} type - The admonition type.
* @param {import('mdast').RootContent[]} children - The children elements of the component.
* @returns {import('mdast').Parent} The created admonition component.
*/
export function AdmonitionComponent(properties, children, type) {
if (!Array.isArray(children) || children.length === 0)
return h("div",
{ class: 'hidden' },
'Invalid admonition directive. (Admonition directives must be of block type ":::note{name="name"} <content> :::")'
);
const title = properties?.title;
return h(`blockquote`,
{ class: `admonition bdm-${type}` },
[ h("span", { class: `bdm-title` }, title ? title : type.toUpperCase()), ...children]
);
}