@prezly/theme-kit-ui
Version:
UI components for Prezly themes
67 lines • 1.98 kB
JavaScript
function prependAtToUsername(username) {
if (username.startsWith('@')) {
return username;
}
return "@".concat(username);
}
function getSocialLink(socialNetwork, url) {
if (!url || url.startsWith('http') || url.startsWith('www')) {
return url;
}
switch (socialNetwork) {
case 'facebook':
return "https://facebook.com/".concat(url);
case 'instagram':
return "https://instagram.com/".concat(url, "/");
case 'linkedin':
return "https://linkedin.com/in/".concat(url);
case 'pinterest':
return "https://pinterest.com/".concat(url);
case 'tiktok':
return "https://tiktok.com/".concat(prependAtToUsername(url));
case 'twitter':
return "https://twitter.com/".concat(url);
case 'youtube':
return "https://youtube.com/".concat(url);
default:
return null;
}
}
export function getSocialLinks(companyInformation) {
var {
facebook,
instagram,
linkedin,
pinterest,
tiktok,
twitter,
youtube
} = companyInformation;
return {
facebook: getSocialLink('facebook', facebook),
instagram: getSocialLink('instagram', instagram),
linkedin: getSocialLink('linkedin', linkedin),
pinterest: getSocialLink('pinterest', pinterest),
tiktok: getSocialLink('tiktok', tiktok),
twitter: getSocialLink('twitter', twitter),
youtube: getSocialLink('youtube', youtube)
};
}
export function getSocialShareUrl(network, url) {
var encodedUrl = encodeURI(url);
if (!encodedUrl) {
return undefined;
}
switch (network) {
case 'facebook':
return "https://www.facebook.com/sharer.php?u=".concat(encodedUrl);
case 'linkedin':
return "https://www.linkedin.com/shareArticle?url=".concat(encodedUrl);
case 'pinterest':
return "http://pinterest.com/pin/create/button/?url=".concat(encodedUrl);
case 'twitter':
return "https://twitter.com/intent/tweet?url=".concat(encodedUrl);
default:
return undefined;
}
}