UNPKG

@telefonica/markdown-confluence-sync

Version:

Creates/updates/deletes Confluence pages based on markdown files in a directory. Supports Mermaid diagrams and per-page configuration using frontmatter metadata. Works great with Docusaurus

33 lines (32 loc) 1.2 kB
// SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital // SPDX-License-Identifier: Apache-2.0 import path from "node:path"; import { visit } from "unist-util-visit"; function isLocalImage(node) { return (node.tagName.toLowerCase() === "img" && node.properties != null && "src" in node.properties && typeof node.properties.src === "string" && !node.properties.src.startsWith("http")); } /** * Plugin to add attachments images in frontmatter */ const rehypeAddAttachmentsImages = function rehypeAddAttachmentsImages() { return function (tree, file) { const images = {}; visit(tree, "element", function (node) { if (isLocalImage(node)) { const base = file.dirname ? path.resolve(file.cwd, file.dirname) : file.cwd; const url = path.resolve(base, node.properties?.src); const baseName = path.basename(url); images[baseName] = url; node.properties = { ...node.properties, src: baseName }; } }); file.data.images = images; }; }; export default rehypeAddAttachmentsImages;