-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
38 lines (31 loc) · 862 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { visit } from 'unist-util-visit';
import resolve from './map-gw2-ids.js';
function attrToProps(attr) {
const props = {};
if (attr) {
attr.forEach((attr) => (props[attr.name] = attr.value));
}
return props;
}
export default () => {
return (markdownAST) => {
const gw2uitypes = ['Skill', 'Trait', 'Item'];
visit(markdownAST, (node) => {
const componentType = node.name;
if (gw2uitypes.includes(componentType)) {
const resolvedProps = resolve(
componentType,
attrToProps(node.attributes),
);
if (!resolvedProps) {
return;
}
node.attributes = [
...node.attributes.filter((attr) => attr.name !== 'id'),
{ type: 'mdxJsxAttribute', name: 'id', value: resolvedProps.id },
];
}
});
return markdownAST;
};
};