@automattic/social-previews
Version:
A suite of components to generate previews for a post for both social and search engines.
10 lines • 665 B
JavaScript
import { firstValid, hardTruncation, shortEnough, stripHtmlTags } from '../helpers';
const TITLE_LENGTH = 110;
const DESCRIPTION_LENGTH = 200;
export const CUSTOM_TEXT_LENGTH = 440;
export const baseDomain = (url) => url
.replace(/^[^/]+[/]*/, '') // strip leading protocol
.replace(/\/.*$/, ''); // strip everything after the domain
export const facebookTitle = (text) => firstValid(shortEnough(TITLE_LENGTH), hardTruncation(TITLE_LENGTH))(stripHtmlTags(text)) || '';
export const facebookDescription = (text) => firstValid(shortEnough(DESCRIPTION_LENGTH), hardTruncation(DESCRIPTION_LENGTH))(stripHtmlTags(text)) || '';
//# sourceMappingURL=helpers.js.map