@automattic/social-previews 3.1.2 → 3.1.3

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/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.1.3] - 2026-04-13
9
+ ### Changed
10
+ - Update package dependencies. [#47890]
11
+
12
+ ### Fixed
13
+ - Google Search preview: Show a generic globe placeholder when the site has no site icon, instead of a broken image. [#48039]
14
+
8
15
  ## [3.1.2] - 2026-04-06
9
16
  ### Changed
10
17
  - Update package dependencies. [#47886]
@@ -159,6 +166,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
159
166
 
160
167
  - Initial release after extracting from Calypso.
161
168
 
169
+ [3.1.3]: https://github.com/Automattic/social-previews/compare/v3.1.2...v3.1.3
162
170
  [3.1.2]: https://github.com/Automattic/social-previews/compare/v3.1.1...v3.1.2
163
171
  [3.1.1]: https://github.com/Automattic/social-previews/compare/v3.1.0...v3.1.1
164
172
  [3.1.0]: https://github.com/Automattic/social-previews/compare/v3.0.12...v3.1.0
package/dist/index.js CHANGED
@@ -101,6 +101,69 @@ function preparePreviewText(text, options) {
101
101
  return _element.createInterpolateElement.call(void 0, result, componentMap);
102
102
  }
103
103
 
104
+ // src/site-icon-with-fallback.tsx
105
+ var _react = require('react');
106
+
107
+ // src/icons/globe-icon.tsx
108
+
109
+ function GlobeIcon(props) {
110
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
111
+ "svg",
112
+ {
113
+ focusable: "false",
114
+ "aria-hidden": "true",
115
+ xmlns: "http://www.w3.org/2000/svg",
116
+ viewBox: "0 0 24 24",
117
+ width: "14",
118
+ height: "14",
119
+ ...props,
120
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
121
+ "path",
122
+ {
123
+ fill: "currentColor",
124
+ d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"
125
+ }
126
+ )
127
+ }
128
+ );
129
+ }
130
+
131
+ // src/site-icon-with-fallback.tsx
132
+
133
+ function DefaultSiteIcon({ className }) {
134
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
135
+ "span",
136
+ {
137
+ className,
138
+ "aria-hidden": "true",
139
+ style: {
140
+ display: "inline-flex",
141
+ alignItems: "center",
142
+ justifyContent: "center",
143
+ backgroundColor: "#e8eaed",
144
+ color: "#5f6368",
145
+ borderRadius: "50%"
146
+ },
147
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobeIcon, { style: { width: "60%", height: "60%" } })
148
+ }
149
+ );
150
+ }
151
+ function SiteIconWithFallback({
152
+ src: siteIconUrl,
153
+ alt = "",
154
+ className,
155
+ fallback = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DefaultSiteIcon, { className })
156
+ }) {
157
+ const [imageUrlWithError, setImageUrlWithError] = _react.useState.call(void 0, "");
158
+ const onError = _react.useCallback.call(void 0, (event) => {
159
+ setImageUrlWithError(event.target.src);
160
+ }, []);
161
+ const showIcon = siteIconUrl && // Check if the image URL with error is different from the provided site icon URL
162
+ // to ensure that a change in siteIconUrl resets the error state
163
+ imageUrlWithError !== siteIconUrl;
164
+ return showIcon ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: siteIconUrl, alt, onError, className }) : fallback;
165
+ }
166
+
104
167
  // src/google-search-preview/index.tsx
105
168
 
106
169
  var URL_LENGTH = 68;
@@ -133,14 +196,7 @@ var GoogleSearchPreview = ({
133
196
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "search-preview", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "search-preview__display", children: [
134
197
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "search-preview__header", children: [
135
198
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "search-preview__branding", children: [
136
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
137
- "img",
138
- {
139
- className: "search-preview__icon",
140
- src: siteIcon || `https://www.google.com/s2/favicons?sz=128&domain_url=${domain}`,
141
- alt: ""
142
- }
143
- ),
199
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SiteIconWithFallback, { className: "search-preview__icon", src: siteIcon }),
144
200
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "search-preview__site", children: [
145
201
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "search-preview__site--title", children: siteTitle || domain }),
146
202
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "search-preview__url", children: googleUrl(url) })
@@ -207,7 +263,7 @@ var Header = ({ name, screenName, date }) => {
207
263
 
208
264
  // src/twitter-preview/media.tsx
209
265
 
210
- var _react = require('react');
266
+
211
267
 
212
268
  var Media = ({ media }) => {
213
269
  const filteredMedia = media.filter(
@@ -1241,7 +1297,7 @@ var card_default = MastodonPostCard;
1241
1297
 
1242
1298
  // src/mastodon-preview/post/icons/index.tsx
1243
1299
 
1244
- function GlobeIcon() {
1300
+ function GlobeIcon2() {
1245
1301
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1246
1302
  "svg",
1247
1303
  {
@@ -1269,7 +1325,7 @@ var MastodonPostHeader = ({ user }) => {
1269
1325
  ] })
1270
1326
  ] }),
1271
1327
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "mastodon-preview__post-header-audience", children: [
1272
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobeIcon, {}),
1328
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobeIcon2, {}),
1273
1329
  formatMastodonDate(/* @__PURE__ */ new Date())
1274
1330
  ] })
1275
1331
  ] });
@@ -1495,7 +1551,7 @@ function DefaultImage() {
1495
1551
 
1496
1552
  // src/nextdoor-preview/icons/globe-icon.tsx
1497
1553
 
1498
- function GlobeIcon2() {
1554
+ function GlobeIcon3() {
1499
1555
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "14", height: "14", fill: "none", viewBox: "0 0 24 24", "aria-hidden": "true", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1500
1556
  "path",
1501
1557
  {
@@ -1530,7 +1586,7 @@ function NextdoorPostPreview({
1530
1586
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "\u2022" }),
1531
1587
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: formatNextdoorDate(Date.now()) }),
1532
1588
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "\u2022" }),
1533
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobeIcon2, {})
1589
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobeIcon3, {})
1534
1590
  ] })
1535
1591
  ] })
1536
1592
  ] }),