mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 07:12:52 +01:00
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:
26
src/plugins/rehype-component-admonition.mjs
Normal file
26
src/plugins/rehype-component-admonition.mjs
Normal 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]
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user