@automattic/social-previews
Version:
A suite of components to generate previews for a post for both social and search engines.
32 lines • 1.46 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { stripHtmlTags } from '../../../helpers';
import { getMastodonAddressDetails, mastodonBody, mastodonUrl } from '../../helpers';
import './styles.scss';
const MastonPostBody = (props) => {
const { title, description, customText, url, user, children } = props;
const instance = user?.address ? getMastodonAddressDetails(user.address).instance : '';
const options = {
instance,
offset: 0,
};
let bodyTxt;
if (customText) {
bodyTxt = _jsx("p", { children: mastodonBody(customText, options) });
}
else if (description) {
if (title) {
const renderedTitle = stripHtmlTags(title);
options.offset = renderedTitle.length;
bodyTxt = (_jsxs(_Fragment, { children: [_jsx("p", { children: renderedTitle }), _jsx("p", { children: mastodonBody(description, options) })] }));
}
else {
bodyTxt = _jsx("p", { children: mastodonBody(description, options) });
}
}
else {
bodyTxt = _jsx("p", { children: mastodonBody(title, options) });
}
return (_jsxs("div", { className: "mastodon-preview__body", children: [bodyTxt, _jsx("a", { href: url, target: "_blank", rel: "noreferrer noopener", children: mastodonUrl(url.replace(/^https?:\/\//, '')) }), children] }));
};
export default MastonPostBody;
//# sourceMappingURL=index.js.map