reference/scripts/utils/rehypeTitle.mjs
2022-10-29 00:24:39 +08:00

19 lines
668 B
JavaScript

import fs from 'fs-extra';
import path from 'path';
import { getSVGNode, ICONS_PATH } from './getSVGNode.mjs';
export function rehypeTitle(node, iconName) {
if (node.type === 'element' && node.tagName === 'h1' && iconName !== 'index') {
const iconPath = path.resolve(ICONS_PATH, `${iconName}.svg`);
const iconDefaultPath = path.resolve(ICONS_PATH, `list.svg`);
const iconExist = fs.existsSync(iconPath);
if (iconExist) {
const svgNode = getSVGNode(iconPath);
node.children = [...svgNode, ...node.children];
} else {
const svgNode = getSVGNode(iconDefaultPath);
node.children = [...svgNode, ...node.children];
}
}
}