@automattic/social-previews
Version:
A suite of components to generate previews for a post for both social and search engines.
17 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Card = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const clsx_1 = tslib_1.__importDefault(require("clsx"));
const helpers_1 = require("../helpers");
const DESCRIPTION_LENGTH = 200;
const twitterDescription = (0, helpers_1.firstValid)((0, helpers_1.shortEnough)(DESCRIPTION_LENGTH), (0, helpers_1.hardTruncation)(DESCRIPTION_LENGTH));
const Card = ({ description, image, title, cardType, url, }) => {
const cardClassNames = (0, clsx_1.default)(`twitter-preview__card-${cardType}`, {
'twitter-preview__card-has-image': !!image,
});
return ((0, jsx_runtime_1.jsx)("div", { className: "twitter-preview__card", children: (0, jsx_runtime_1.jsxs)("div", { className: cardClassNames, children: [image && (0, jsx_runtime_1.jsx)("img", { className: "twitter-preview__card-image", src: image, alt: "" }), (0, jsx_runtime_1.jsxs)("div", { className: "twitter-preview__card-body", children: [(0, jsx_runtime_1.jsx)("div", { className: "twitter-preview__card-url", children: (0, helpers_1.baseDomain)(url || '') }), (0, jsx_runtime_1.jsx)("div", { className: "twitter-preview__card-title", children: title }), (0, jsx_runtime_1.jsx)("div", { className: "twitter-preview__card-description", children: twitterDescription((0, helpers_1.stripHtmlTags)(description)) })] })] }) }));
};
exports.Card = Card;
//# sourceMappingURL=card.js.map