@tryghost/mg-substack 0.4.3 → 0.5.1

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.
Files changed (2) hide show
  1. package/lib/process.js +107 -7
  2. package/package.json +4 -4
package/lib/process.js CHANGED
@@ -231,16 +231,40 @@ const processContent = (post, siteUrl, options) => {
231
231
  }
232
232
  src = url.format(parsed, {search: false});
233
233
 
234
- let tweetText = $(el).find('.tweet-text').html().replace(/(?:\r\n|\r|\n)/g, '<br>');
235
- let tweetAuthorName = $(el).find('.tweet-author-name').html().trim();
236
- let tweetAuthorHandle = $(el).find('.tweet-author-handle').html().trim();
237
- let tweetDateTime = $(el).find('.tweet-date').text().trim();
238
- let tweetURL = $(el).find('.tweet-link-top').attr('href');
234
+ let tweetText = $(el)?.find('.tweet-text')?.html()?.replace(/(?:\r\n|\r|\n)/g, '<br>') ?? false;
235
+ let tweetAuthorName = $(el)?.find('.tweet-author-name')?.html()?.trim() ?? false;
236
+ let tweetAuthorHandle = $(el)?.find('.tweet-author-handle')?.html()?.trim() ?? false;
237
+ let tweetDateTime = $(el)?.find('.tweet-date')?.text()?.trim() ?? false;
238
+ let tweetURL = $(el)?.find('.tweet-link-top')?.attr('href') ?? false;
239
239
 
240
- let theHtml = `<p lang="en" dir="ltr">${tweetText}</p>&mdash; ${tweetAuthorName} (${tweetAuthorHandle}) <a href="${tweetURL}">${tweetDateTime}</a>`;
240
+ let theHtml = [];
241
+
242
+ if (tweetText) {
243
+ theHtml.push(`<p lang="en" dir="ltr">${tweetText}</p>`);
244
+ }
245
+
246
+ theHtml.push(`&mdash;`);
247
+
248
+ if (tweetAuthorName) {
249
+ theHtml.push(`${tweetAuthorName}`);
250
+ }
251
+
252
+ if (tweetAuthorHandle) {
253
+ theHtml.push(`(${tweetAuthorHandle})`);
254
+ }
255
+
256
+ if (tweetURL) {
257
+ theHtml.push(`<a href="${tweetURL}">`);
258
+ }
259
+
260
+ if (tweetDateTime) {
261
+ theHtml.push(`${tweetDateTime}`);
262
+ }
263
+
264
+ theHtml.push(`</a>`);
241
265
 
242
266
  let $figure = $('<figure class="kg-card kg-embed-card"></figure>');
243
- let $blockquote = $(`<blockquote class="twitter-tweet">${theHtml}</blockquote>`);
267
+ let $blockquote = $(`<blockquote class="twitter-tweet">${theHtml.join(' ')}</blockquote>`);
244
268
  let $anchor = $(`<a href="${src}"></a>`);
245
269
  let $script = $('<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>');
246
270
 
@@ -372,6 +396,82 @@ const processContent = (post, siteUrl, options) => {
372
396
  $(anchor).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
373
397
  });
374
398
 
399
+ $html('.digest-post-embed').each((i, el) => {
400
+ const attrsRaw = $(el).attr('data-attrs');
401
+ const attrs = JSON.parse(attrsRaw);
402
+
403
+ let theHtml = [];
404
+
405
+ if (attrs.section_name) {
406
+ theHtml.push(`<h6>${attrs.section_name}</h6>`);
407
+ }
408
+
409
+ if (attrs.title) {
410
+ theHtml.push(`<h3>`);
411
+
412
+ if (attrs.canonical_url) {
413
+ theHtml.push(`<a href="${attrs.canonical_url}">`);
414
+ }
415
+
416
+ theHtml.push(attrs.title);
417
+
418
+ if (attrs.canonical_url) {
419
+ theHtml.push(`</a>`);
420
+ }
421
+
422
+ theHtml.push(`</h3>`);
423
+ }
424
+
425
+ if (attrs.publishedBylines.length || attrs.post_date) {
426
+ theHtml.push(`<p>`);
427
+
428
+ if (attrs.publishedBylines) {
429
+ let bylines = [];
430
+
431
+ attrs.publishedBylines.forEach((byline) => {
432
+ bylines.push(byline.name);
433
+ });
434
+
435
+ theHtml.push(bylines.join(', '));
436
+ }
437
+
438
+ if (attrs.publishedBylines.length && attrs.post_date) {
439
+ theHtml.push(` &bull; `);
440
+ }
441
+
442
+ if (attrs.post_date) {
443
+ theHtml.push(new Date(attrs.post_date).toLocaleString('en-US', {month: 'short', day: 'numeric', year: 'numeric'}));
444
+ }
445
+
446
+ theHtml.push(`</p>`);
447
+ }
448
+
449
+ if (attrs.cover_image) {
450
+ if (attrs.canonical_url) {
451
+ theHtml.push(`<a href="${attrs.canonical_url}">`);
452
+ }
453
+
454
+ theHtml.push(`<img src="${attrs.cover_image}" alt="${attrs.cover_image_alt || ''}">`);
455
+
456
+ if (attrs.canonical_url) {
457
+ theHtml.push(`</a>`);
458
+ }
459
+ }
460
+
461
+ if (attrs.caption) {
462
+ theHtml.push(`<p>`);
463
+ theHtml.push(attrs.caption);
464
+
465
+ if (attrs.canonical_url) {
466
+ theHtml.push(`<br><br><a href="${attrs.canonical_url}">Read full story &rarr;</a>`);
467
+ }
468
+
469
+ theHtml.push(`</p>`);
470
+ }
471
+
472
+ $(el).replaceWith(theHtml.join(''));
473
+ });
474
+
375
475
  $html('a > style').each((i, style) => {
376
476
  $(style).remove();
377
477
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@tryghost/debug": "0.1.27",
29
29
  "@tryghost/errors": "1.3.0",
30
- "@tryghost/kg-default-cards": "10.0.1",
30
+ "@tryghost/kg-default-cards": "10.0.2",
31
31
  "@tryghost/mg-fs-utils": "^0.13.0",
32
32
  "@tryghost/string": "0.2.11",
33
33
  "cheerio": "1.0.0-rc.12",
@@ -36,7 +36,7 @@
36
36
  "html-entities": "2.4.0",
37
37
  "lodash": "4.17.21",
38
38
  "simple-dom": "1.4.0",
39
- "srcset": "5.0.0"
39
+ "srcset": "5.0.1"
40
40
  },
41
- "gitHead": "73234756d0188f35dac8de168ed4a27148c7d971"
41
+ "gitHead": "db762af916ae75789b139f59220b621ec9d732c7"
42
42
  }