@automattic/social-previews 1.0.4 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,53 +1,59 @@
1
1
  {
2
- "name": "@automattic/social-previews",
3
- "version": "1.0.4",
4
- "description": "A suite of components to generate previews for a post for both social and search engines",
5
- "main": "dist/cjs/index.js",
6
- "module": "dist/esm/index.js",
7
- "sideEffects": [
8
- "*.css",
9
- "*.scss"
10
- ],
11
- "keywords": [
12
- "wordpress",
13
- "social",
14
- "seo",
15
- "search"
16
- ],
17
- "author": "Automattic Inc.",
18
- "homepage": "https://github.com/Automattic/wp-calypso",
19
- "license": "GPL-2.0-or-later",
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/Automattic/wp-calypso.git",
23
- "directory": "packages/social-previews"
24
- },
25
- "publishConfig": {
26
- "access": "public"
27
- },
28
- "bugs": {
29
- "url": "https://github.com/Automattic/wp-calypso/issues"
30
- },
31
- "files": [
32
- "dist",
33
- "src"
34
- ],
35
- "scripts": {
36
- "clean": "npx rimraf dist",
37
- "prepublish": "yarn run clean",
38
- "prepare": "transpile && copy-assets"
39
- },
40
- "dependencies": {
41
- "@babel/runtime": "^7.11.1",
42
- "lodash": "^4.17.15",
43
- "prop-types": "^15.7.2"
44
- },
45
- "devDependencies": {
46
- "@automattic/calypso-build": "^6.1.0",
47
- "enzyme": "^3.11.0"
48
- },
49
- "peerDependencies": {
50
- "react": "^16.12.0"
51
- },
52
- "gitHead": "2bbc6a9014676a625c6f28df4c2357d333ff6c28"
53
- }
2
+ "name": "@automattic/social-previews",
3
+ "version": "1.1.2",
4
+ "description": "A suite of components to generate previews for a post for both social and search engines.",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "calypso:src": "src/index.js",
8
+ "sideEffects": [
9
+ "*.css",
10
+ "*.scss"
11
+ ],
12
+ "keywords": [
13
+ "wordpress",
14
+ "social",
15
+ "seo",
16
+ "search"
17
+ ],
18
+ "author": "Automattic Inc.",
19
+ "homepage": "https://github.com/Automattic/wp-calypso",
20
+ "license": "GPL-2.0-or-later",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Automattic/wp-calypso.git",
24
+ "directory": "packages/social-previews"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "bugs": "https://github.com/Automattic/wp-calypso/issues",
30
+ "files": [
31
+ "dist",
32
+ "src"
33
+ ],
34
+ "scripts": {
35
+ "clean": "rm -rf dist",
36
+ "build": "transpile && copy-assets",
37
+ "prepack": "yarn run clean && yarn run build"
38
+ },
39
+ "dependencies": {
40
+ "@wordpress/components": "^19.9.0",
41
+ "@wordpress/i18n": "^4.7.0",
42
+ "classnames": "^2.3.1",
43
+ "lodash": "^4.17.21",
44
+ "moment": "^2.26.0",
45
+ "prop-types": "^15.7.2"
46
+ },
47
+ "devDependencies": {
48
+ "@automattic/calypso-typescript-config": "^1.0.0",
49
+ "enzyme": "^3.11.0",
50
+ "react": "^17.0.2",
51
+ "react-dom": "^17.0.2"
52
+ },
53
+ "peerDependencies": {
54
+ "@wordpress/data": "^6.7.0",
55
+ "react": "^17.0.2",
56
+ "reakit-utils": "^0.15.1",
57
+ "redux": "^4.1.2"
58
+ }
59
+ }
@@ -1,15 +1,8 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
- import PropTypes from 'prop-types';
6
- import React, { PureComponent } from 'react';
7
1
  import { compact } from 'lodash';
2
+ import PropTypes from 'prop-types';
3
+ import { PureComponent } from 'react';
8
4
  import { firstValid, hardTruncation, shortEnough, stripHtmlTags } from '../helpers';
9
5
 
10
- /**
11
- * Style dependencies
12
- */
13
6
  import './style.scss';
14
7
 
15
8
  const TITLE_LENGTH = 80;
package/src/helpers.js CHANGED
@@ -1,10 +1,6 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
1
  import { find } from 'lodash';
6
2
 
7
- export const shortEnough = ( limit ) => ( title ) => ( title.length <= limit ? title : false );
3
+ export const shortEnough = ( limit ) => ( title ) => title.length <= limit ? title : false;
8
4
 
9
5
  export const truncatedAtSpace = ( lower, upper ) => ( fullTitle ) => {
10
6
  const title = fullTitle.slice( 0, upper );
@@ -15,8 +11,10 @@ export const truncatedAtSpace = ( lower, upper ) => ( fullTitle ) => {
15
11
 
16
12
  export const hardTruncation = ( limit ) => ( title ) => title.slice( 0, limit ).concat( '…' );
17
13
 
18
- export const firstValid = ( ...predicates ) => ( a ) =>
19
- find( predicates, ( p ) => false !== p( a ) )( a );
14
+ export const firstValid =
15
+ ( ...predicates ) =>
16
+ ( a ) =>
17
+ find( predicates, ( p ) => false !== p( a ) )( a );
20
18
 
21
19
  export const stripHtmlTags = ( description ) =>
22
20
  description ? description.replace( /(<([^>]+)>)/gi, '' ) : '';
@@ -1,9 +1,4 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
1
  import PropTypes from 'prop-types';
6
- import React from 'react';
7
2
  import {
8
3
  firstValid,
9
4
  hardTruncation,
@@ -12,9 +7,6 @@ import {
12
7
  stripHtmlTags,
13
8
  } from '../helpers';
14
9
 
15
- /**
16
- * Style dependencies
17
- */
18
10
  import './style.scss';
19
11
 
20
12
  const URL_LENGTH = 68;
@@ -1,64 +1,49 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
1
  import PropTypes from 'prop-types';
6
- import React, { PureComponent } from 'react';
7
-
8
- /**
9
- * Internal dependencies
10
- */
2
+ import { PureComponent } from 'react';
3
+ import { Tweet } from './tweet';
11
4
 
12
- import { firstValid, hardTruncation, shortEnough, stripHtmlTags } from '../helpers';
13
-
14
- /**
15
- * Style dependencies
16
- */
17
5
  import './style.scss';
18
6
 
19
- const DESCRIPTION_LENGTH = 200;
20
-
21
- const baseDomain = ( url ) =>
22
- url
23
- .replace( /^[^/]+[/]*/, '' ) // strip leading protocol
24
- .replace( /\/.*$/, '' ); // strip everything after the domain
25
-
26
- const twitterDescription = firstValid(
27
- shortEnough( DESCRIPTION_LENGTH ),
28
- hardTruncation( DESCRIPTION_LENGTH )
29
- );
30
-
31
7
  export class TwitterPreview extends PureComponent {
32
8
  render() {
33
- const { url, title, type, description, image } = this.props;
34
-
35
- const previewImageStyle = {
36
- backgroundImage: 'url(' + image + ')',
37
- };
9
+ // Previous versions expected passed props to be the Twitter Card details for a single tweet,
10
+ // rather than an array of tweets. If the tweet array isn't passed, we can construct it from
11
+ // the old props.
12
+ const tweets = this.props.tweets || [
13
+ {
14
+ text: '',
15
+ media: [],
16
+ card: {
17
+ ...this.props,
18
+ type: 'large_image_summary' === this.props.type ? 'summary_large_image' : this.props.type,
19
+ },
20
+ date: Date.now(),
21
+ name: 'Account Name',
22
+ profileImage:
23
+ 'https://abs.twimg.com/sticky/default_profile_images/default_profile_bigger.png',
24
+ screenName: '@account',
25
+ },
26
+ ];
38
27
 
39
28
  return (
40
29
  <div className="twitter-preview">
41
- <div className={ `twitter-preview__${ type }` }>
42
- { image && <div className="twitter-preview__image" style={ previewImageStyle } /> }
43
- <div className="twitter-preview__body">
44
- <div className="twitter-preview__title">{ title }</div>
45
- <div className="twitter-preview__description">
46
- { twitterDescription( stripHtmlTags( description ) ) }
47
- </div>
48
- <div className="twitter-preview__url">{ baseDomain( url || '' ) }</div>
49
- </div>
50
- </div>
30
+ { tweets &&
31
+ tweets.map( ( tweet, index ) => {
32
+ return (
33
+ <Tweet
34
+ key={ `twitter-preview__tweet-${ index }` }
35
+ isLast={ index + 1 === tweets.length }
36
+ { ...tweet }
37
+ />
38
+ );
39
+ } ) }
51
40
  </div>
52
41
  );
53
42
  }
54
43
  }
55
44
 
56
45
  TwitterPreview.propTypes = {
57
- url: PropTypes.string,
58
- title: PropTypes.string,
59
- type: PropTypes.string,
60
- description: PropTypes.string,
61
- image: PropTypes.string,
46
+ tweets: PropTypes.array,
62
47
  };
63
48
 
64
49
  export default TwitterPreview;
@@ -1,112 +1,228 @@
1
1
  /*
2
2
  * CSS values in this file are specific and
3
- * designed to match the CSS on external sites,
4
- * such as Google and Facebook. Therefore there
3
+ * designed to match the CSS on Twitter. Therefore there
5
4
  * will be exceptions to our CSS guidelines here
6
- * but please do not "update" this file to
7
- * conform.
5
+ * but please do not "update" this file to conform.
8
6
  *
9
- * @blame: dmsnell
10
- */
7
+ * @blame: pento
8
+ */
11
9
 
12
10
  @import '../variables.scss';
13
11
 
14
12
  /* stylelint-disable scales/font-size */
15
13
 
16
14
  .twitter-preview {
15
+ background-color: #fff;
17
16
  padding: 20px;
18
- box-sizing: border-box;
17
+ width: 635px;
19
18
  }
20
19
 
21
- .twitter-preview__summary,
22
- .twitter-preview__large_image_summary {
23
- width: 506px;
24
- max-width: 100%;
25
- margin: 0 auto;
26
- overflow: hidden;
27
- border: 1px solid #e1e8ed;
28
- border-radius: 12px;
29
- }
30
-
31
- .twitter-preview__summary {
32
- height: 125px;
33
- }
34
-
35
- .twitter-preview__large_image_summary {
36
- height: auto;
37
- }
38
-
39
- .twitter-preview__image {
40
- background-size: cover;
41
- background-position: center;
42
- }
43
-
44
- .twitter-preview__summary .twitter-preview__image {
45
- float: left;
46
- width: 125px;
47
- height: 125px;
48
- }
49
-
50
- .twitter-preview__large_image_summary .twitter-preview__image {
51
- width: 506px;
52
- max-width: 100%;
53
- height: 254px;
54
- border-bottom: 1px solid #e1e8ed;
55
- }
56
-
57
- .twitter-preview__body {
58
- padding: 0.75em;
59
- text-decoration: none;
60
- font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
61
- font-size: $font-body-small;
62
- color: black;
63
- text-align: left;
64
- line-height: 1.3em;
65
- overflow: hidden;
66
- }
67
-
68
- .twitter-preview__summary .twitter-preview__body {
69
- margin-left: 125px;
70
- border-left: 1px solid #e1e8ed;
71
- height: 100%;
72
- }
73
-
74
- .twitter-preview__large_image_summary .twitter-preview__body {
75
- padding-left: 1em;
76
- padding-right: 1em;
77
- }
78
-
79
- .twitter-preview__title {
80
- max-height: 1.3em;
81
- white-space: nowrap;
82
- font-weight: bold;
83
- font-size: 1em;
84
- margin: 0 0 0.15em;
85
- overflow: hidden;
86
- text-overflow: ellipsis;
87
- }
88
-
89
- .twitter-preview__description {
90
- margin-top: 0.32333em;
91
- max-height: 3.9em;
92
- text-overflow: ellipsis;
93
- //clamp after two lines
94
- display: -webkit-box;
95
- -webkit-line-clamp: 2;
96
- -webkit-box-orient: vertical;
97
- overflow: hidden;
98
- }
99
-
100
- .twitter-preview__summary .twitter-preview__description {
101
- -webkit-line-clamp: 3;
102
- }
103
-
104
- .twitter-preview__url {
105
- text-transform: lowercase;
106
- color: #8899a6;
107
- max-height: 1.3em;
108
- white-space: nowrap;
109
- overflow: hidden;
110
- text-overflow: ellipsis;
111
- margin-top: 0.32333em;
20
+ .twitter-preview__container {
21
+ display: grid;
22
+ grid-template-columns: 65px auto;
23
+ margin-bottom: 5px;
24
+ margin-right: 24px;
25
+
26
+ .twitter-preview__sidebar {
27
+ display: grid;
28
+ grid-template-rows: 35px auto;
29
+ justify-items: center;
30
+
31
+ .twitter-preview__profile-image {
32
+ img {
33
+ height: 30px;
34
+ width: 30px;
35
+ border-radius: 15px;
36
+ object-fit: cover;
37
+ }
38
+ }
39
+
40
+ .twitter-preview__connector {
41
+ width: 2px;
42
+ background-color: #8c8f94;
43
+ }
44
+ }
45
+
46
+ .twitter-preview__name {
47
+ font-weight: bold;
48
+ font-size: 16px;
49
+ line-height: 19px;
50
+ }
51
+
52
+ .twitter-preview__screen-name,
53
+ .twitter-preview__date {
54
+ color: #667886;
55
+ font-size: 16px;
56
+ line-height: 18px;
57
+ letter-spacing: -0.3px;
58
+ margin-left: 15px;
59
+ }
60
+
61
+ .twitter-preview__content {
62
+ margin: 7px 0;
63
+
64
+ .twitter-preview__text {
65
+ font-size: 14px;
66
+ line-height: 18px;
67
+ letter-spacing: -0.3px;
68
+ color: #787c82;
69
+ white-space: pre-wrap;
70
+ word-break: break-word;
71
+ }
72
+
73
+ .twitter-preview__media {
74
+ border-radius: 15px;
75
+ overflow: hidden;
76
+ display: grid;
77
+ grid-gap: 2px;
78
+ grid-template-areas: 'a';
79
+ height: 300px;
80
+ margin-top: 10px;
81
+
82
+ img,
83
+ video {
84
+ width: 100%;
85
+ height: 100%;
86
+ object-fit: cover;
87
+
88
+ &:nth-child( 1 ) {
89
+ grid-area: a;
90
+ }
91
+ &:nth-child( 2 ) {
92
+ grid-area: b;
93
+ }
94
+ &:nth-child( 3 ) {
95
+ grid-area: c;
96
+ }
97
+ &:nth-child( 4 ) {
98
+ grid-area: d;
99
+ }
100
+ }
101
+
102
+ &.twitter-preview__media-children-2 {
103
+ grid-template-areas: 'a b';
104
+ }
105
+
106
+ &.twitter-preview__media-children-3 {
107
+ grid-template-areas: 'a b'
108
+ 'a c';
109
+ }
110
+
111
+ &.twitter-preview__media-children-4 {
112
+ grid-template-areas: 'a b'
113
+ 'c d';
114
+ }
115
+ }
116
+
117
+ .twitter-preview__quote-tweet {
118
+ margin-top: 10px;
119
+ min-height: 200px;
120
+
121
+ .twitter-preview__quote-tweet-overlay {
122
+ position: absolute;
123
+ top: 0;
124
+ left: 0;
125
+ right: 0;
126
+ bottom: 0;
127
+ opacity: 0;
128
+ }
129
+ }
130
+
131
+ .twitter-preview__card {
132
+ margin-top: 10px;
133
+ overflow: hidden;
134
+ border: 1px solid #e1e8ed;
135
+ border-radius: 12px;
136
+
137
+ .twitter-preview__card-summary {
138
+ display: grid;
139
+
140
+ &.twitter-preview__card-has-image {
141
+ height: 125px;
142
+ display: grid;
143
+ grid-template-columns: 125px auto;
144
+
145
+ .twitter-preview__card-body {
146
+ border-left: 1px solid #e1e8ed;
147
+ height: 100%;
148
+ }
149
+
150
+ .twitter-preview__card-description {
151
+ -webkit-line-clamp: 3;
152
+ }
153
+ }
154
+ }
155
+
156
+ .twitter-preview__card-summary_large_image {
157
+ display: grid;
158
+ grid-template-rows: 254px auto;
159
+ }
160
+
161
+ .twitter-preview__card-image {
162
+ width: 100%;
163
+ height: 100%;
164
+ object-fit: cover;
165
+ }
166
+
167
+ .twitter-preview__card-body {
168
+ padding: 0.75em;
169
+ text-decoration: none;
170
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
171
+ font-size: $font-body-small;
172
+ color: black;
173
+ text-align: left;
174
+ line-height: 1.3em;
175
+ overflow: hidden;
176
+ }
177
+
178
+ .twitter-preview__card-title {
179
+ max-height: 1.3em;
180
+ white-space: nowrap;
181
+ font-weight: bold;
182
+ font-size: 1em;
183
+ margin: 0 0 0.15em;
184
+ overflow: hidden;
185
+ text-overflow: ellipsis;
186
+ }
187
+
188
+ .twitter-preview__card-description {
189
+ margin-top: 0.32333em;
190
+ max-height: 3.9em;
191
+ text-overflow: ellipsis;
192
+ //clamp after two lines
193
+ display: -webkit-box;
194
+ -webkit-line-clamp: 2;
195
+ -webkit-box-orient: vertical;
196
+ overflow: hidden;
197
+ }
198
+
199
+ .twitter-preview__card-url {
200
+ text-transform: lowercase;
201
+ color: #8899a6;
202
+ max-height: 1.3em;
203
+ white-space: nowrap;
204
+ overflow-inline: hidden;
205
+ text-overflow: ellipsis;
206
+ margin-top: 0.32333em;
207
+
208
+ svg {
209
+ fill: #8899a6;
210
+ height: 15px;
211
+ width: 15px;
212
+ margin: 0 2px -4px 0;
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ .twitter-preview__footer {
219
+ display: grid;
220
+ grid-template-columns: repeat( 4, auto );
221
+
222
+ svg {
223
+ fill: #787c82;
224
+ height: 16px;
225
+ width: 16px;
226
+ }
227
+ }
112
228
  }