remark custom plugins
This commit is contained in:
parent
fafb0b1c1e
commit
75ee13fe94
|
@ -0,0 +1,22 @@
|
|||
import { visit } from 'unist-util-visit';
|
||||
|
||||
const visitor = (node) => {
|
||||
node.data = node.data || {};
|
||||
node.data.hProperties = node.data.hProperties || {};
|
||||
if (node.type === 'link') {
|
||||
if (
|
||||
node.children &&
|
||||
node.children.length &&
|
||||
node.children.length === 1
|
||||
) {
|
||||
if (node.children[0].type === 'image') {
|
||||
node.data.hProperties.class = 'after:hidden';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default () => async (tree) => {
|
||||
visit(tree, visitor);
|
||||
return tree;
|
||||
};
|
|
@ -0,0 +1,19 @@
|
|||
import { visit } from 'unist-util-visit';
|
||||
|
||||
const imagesRelativeUrlPattern = '/images/';
|
||||
|
||||
const visitor = (node) => {
|
||||
if (node.type === 'image' && node.url.indexOf(imagesRelativeUrlPattern) > 0) {
|
||||
node.url = node.url.substring(node.url.indexOf(imagesRelativeUrlPattern) + ''.length);
|
||||
}
|
||||
};
|
||||
|
||||
export default () => async (tree, vFile) => {
|
||||
if (
|
||||
vFile.filename.indexOf('src/routes/blog/') > 0 ||
|
||||
vFile.filename.indexOf('src/routes/projects/') > 0
|
||||
) {
|
||||
visit(tree, visitor);
|
||||
}
|
||||
return tree;
|
||||
};
|
Loading…
Reference in New Issue