Files
.github
.husky
docs
scripts
assets
nodes
utils
anchorPoint.mjs
childs.mjs
darkMode.mjs
getSVGNode.mjs
getTocsTree.mjs
homeCardIcons.mjs
panelAddNumber.mjs
rehypePreviewHTML.mjs
rehypeTitle.mjs
rehypeUrls.mjs
tooltips.mjs
build.mjs
create.mjs
index.mjs
style.css
watch.mjs
.gitignore
.lintstagedrc
.prettierignore
.prettierrc
CONTRIBUTING.md
Dockerfile
LICENSE
README.md
package.json
renovate.json
reference/scripts/utils/rehypeTitle.mjs

19 lines
668 B
JavaScript
Raw Normal View History

2022-10-15 13:32:12 +08:00
import fs from 'fs-extra';
import path from 'path';
import { getSVGNode, ICONS_PATH } from './getSVGNode.mjs';
2022-10-15 13:32:12 +08:00
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);
2022-10-29 00:24:39 +08:00
node.children = [...svgNode, ...node.children];
2022-10-15 13:32:12 +08:00
} else {
const svgNode = getSVGNode(iconDefaultPath);
2022-10-29 00:24:39 +08:00
node.children = [...svgNode, ...node.children];
2022-10-15 13:32:12 +08:00
}
}
2022-10-29 00:24:39 +08:00
}