UNPKG

gatsby-mdx-remote

Version:

A plugin to transform nodes with mdx content and frontmatter into mdx File nodes for consumption by the gatsby-plugin-mdx plugin

30 lines 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractUrlAndReplaceWithGatsbyImage = void 0; const unist_util_visit_1 = __importDefault(require("unist-util-visit")); const extractUrlAndReplaceWithGatsbyImage = (options) => (tree) => { // We visit only 'image' nodes (0, unist_util_visit_1.default)(tree, "mdxJsxFlowElement", (node) => { console.log(JSON.stringify(node, null, 2)); }); (0, unist_util_visit_1.default)(tree, "image", (node) => { if (node.depth === undefined && node.url) { const index = options.getUrlListLength(); options.pushImageUrlToList(node.url); const providedClassName = options.className ? `className="${options.className}"` : ""; const html = `<GatsbyImage alt="${node.alt}" title="${node.title ?? node.alt}" image={getImage((props.pageContext.markdownImageList && props.pageContext.markdownImageList[${index}])?.childImageSharp?.gatsbyImageData)} ${providedClassName} />\n`; node.type = "html"; node.name = "GatsbyImage"; node.children = undefined; node.value = html; } else { return; } }); }; exports.extractUrlAndReplaceWithGatsbyImage = extractUrlAndReplaceWithGatsbyImage; //# sourceMappingURL=extractUrlAndReplaceWithGatsbyImage.js.map