From e16ec2efb339dfa08c92eebf2ae2fee8e32b4b9f Mon Sep 17 00:00:00 2001 From: Maya Shavin Date: Tue, 15 Dec 2020 13:35:28 +0200 Subject: [PATCH] fix: remove socialCard --- package.json | 2 +- packages/url/__tests__/socialcard.test.ts | 25 ------- packages/url/lib/socialCard.ts | 90 ----------------------- packages/url/package.json | 2 +- 4 files changed, 2 insertions(+), 117 deletions(-) delete mode 100644 packages/url/__tests__/socialcard.test.ts delete mode 100644 packages/url/lib/socialCard.ts diff --git a/package.json b/package.json index 486a66d..bef72f2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "root", + "name": "cloudinary-api", "description": "Shorter and lighter APIs for Cloudinary", "private": true, "workspaces": [ diff --git a/packages/url/__tests__/socialcard.test.ts b/packages/url/__tests__/socialcard.test.ts deleted file mode 100644 index 3f0d21d..0000000 --- a/packages/url/__tests__/socialcard.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { buildSocialCard} from '../lib/socialCard' - -describe('SocialCard', () => { - it('should return a card', () => { - expect(buildSocialCard({ - title: { - value: 'Deploy a Node.js App to DigitalOcean with SSL', - font:'futura', - }, - tagline: { - value: '#devops #nodejs #ssl', - font:'futura', - }, - image: { - publicId: 'lwj/blog-post-card', - }, - text: { - color: '232129', - width: 760, - } - }, { - cloudName: 'jlengstorf' - })).toBe('https://res.cloudinary.com/jlengstorf/image/upload/c_fill,w_1280,h_669,q_auto,f_auto/c_fit,w_760,x_480,y_254,g_south_west,l_text:futura_64:Deploy%20a%20Node.js%20App%20to%20DigitalOcean%20with%20SSL,co_rgb:232129/c_fit,w_760,x_480,y_445,g_north_west,l_text:futura_48:%2523devops%20%2523nodejs%20%2523ssl,co_rgb:232129/lwj/blog-post-card') - }); -}); \ No newline at end of file diff --git a/packages/url/lib/socialCard.ts b/packages/url/lib/socialCard.ts deleted file mode 100644 index dd9009b..0000000 --- a/packages/url/lib/socialCard.ts +++ /dev/null @@ -1,90 +0,0 @@ - -import { cleanText, toString } from './utils' -import { ResizeType, CloudConfig, TransformerOption, SocialCard, SocialImage, SocialText, TextArea } from '@cld-apis/types' -import { buildImageUrl, getConfig } from '.' - -const DEFAULTS = { - TAGLINE: { - font: 'arial', - placementDirection: 'north_west', - size: 48, - position: { - y: 445 - }, - }, - TITLE: { - font: 'arial', - placementDirection: 'south_west', - size: 64, - position: { - y: 254 - }, - }, - - IMAGE: { - width: 1280, - height: 669, - cropMode: 'fill' - }, - TEXT: { - width: 760, - color: '000000', - cropMode: 'fit', - position: { - x: 480 - } - } -} - -const buildSocialTextTransformations = (options: SocialText, defaultOpts: TextArea = DEFAULTS.TEXT):TransformerOption => { - if (!options.value) return {} - - const textOverlay = toString([toString([options.font || defaultOpts.font, options.size || defaultOpts.size], '_'), options.extraConfig], '') - const overlay = toString(['text', textOverlay, cleanText(options.value)]) - const color = toString(['rgb', options.color || defaultOpts.color || DEFAULTS.TEXT.color]) - const position = options.position || defaultOpts.position || {} - - return { - resize: { - width: defaultOpts.width || DEFAULTS.TEXT.width, - type: DEFAULTS.TEXT.cropMode as ResizeType - }, - gravity: options.placementDirection || defaultOpts.placementDirection, - position: { - x: position.x || DEFAULTS.TEXT.position.x, - y: position.y, - }, - overlay, - color - } -} - -export const buildSocialCard = (options: SocialCard, cloud?: CloudConfig) => { - const image:SocialImage = options.image - const tagLineTransformations:TransformerOption = options.tagline ? buildSocialTextTransformations(options.tagline, { - ...(DEFAULTS.TAGLINE as any), - ...(options.text || {}), - }) : {} - const titleTransformations:TransformerOption = buildSocialTextTransformations(options.title, { - ...(DEFAULTS.TITLE as any), - ...(options.text || {}), - }) - - const transformations:TransformerOption = { - resize: { - width: image.width || DEFAULTS.IMAGE.width, - height: image.height || DEFAULTS.IMAGE.height, - type: image.cropMode || DEFAULTS.IMAGE.cropMode as ResizeType - }, - gravity: image.resizeFocus, - chaining: [titleTransformations, tagLineTransformations ] - } - - return buildImageUrl(image.publicId, { - cloud: { - ...getConfig(), - ...cloud - }, - transformations - }) -} diff --git a/packages/url/package.json b/packages/url/package.json index ef573ea..081defa 100644 --- a/packages/url/package.json +++ b/packages/url/package.json @@ -1,6 +1,6 @@ { "name": "cloudinary-build-url", - "version": "0.1.0-alpha.1", + "version": "0.1.1", "description": "Lighter Url generator for Cloudinary", "author": "Maya Shavin ", "license": "MIT",