remark custom plugins

This commit is contained in:
matthieu42morin 2024-03-22 15:00:56 +01:00
parent fafb0b1c1e
commit 75ee13fe94
2 changed files with 41 additions and 0 deletions

View File

@ -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;
};

View File

@ -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;
};