UNPKG

@automattic/social-previews

Version:

A suite of components to generate previews for a post for both social and search engines.

34 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const helpers_1 = require("../../../helpers"); const helpers_2 = require("../../helpers"); require("./styles.scss"); const MastonPostBody = (props) => { const { title, description, customText, url, user, children } = props; const instance = user?.address ? (0, helpers_2.getMastodonAddressDetails)(user.address).instance : ''; const options = { instance, offset: 0, }; let bodyTxt; if (customText) { bodyTxt = (0, jsx_runtime_1.jsx)("p", { children: (0, helpers_2.mastodonBody)(customText, options) }); } else if (description) { if (title) { const renderedTitle = (0, helpers_1.stripHtmlTags)(title); options.offset = renderedTitle.length; bodyTxt = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { children: renderedTitle }), (0, jsx_runtime_1.jsx)("p", { children: (0, helpers_2.mastodonBody)(description, options) })] })); } else { bodyTxt = (0, jsx_runtime_1.jsx)("p", { children: (0, helpers_2.mastodonBody)(description, options) }); } } else { bodyTxt = (0, jsx_runtime_1.jsx)("p", { children: (0, helpers_2.mastodonBody)(title, options) }); } return ((0, jsx_runtime_1.jsxs)("div", { className: "mastodon-preview__body", children: [bodyTxt, (0, jsx_runtime_1.jsx)("a", { href: url, target: "_blank", rel: "noreferrer noopener", children: (0, helpers_2.mastodonUrl)(url.replace(/^https?:\/\//, '')) }), children] })); }; exports.default = MastonPostBody; //# sourceMappingURL=index.js.map