@tryghost/mg-tinynews 0.4.0 → 0.6.0

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/mapper.js +15 -16
  2. package/package.json +3 -3
package/lib/mapper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {readFile} from 'node:fs/promises';
2
2
  import sanitizeHtml from 'sanitize-html';
3
- import * as cheerio from 'cheerio';
3
+ import {domUtils} from '@tryghost/mg-utils';
4
4
  import {slugify} from '@tryghost/string';
5
5
  import {_base as debugFactory} from '@tryghost/debug';
6
6
  import {jsonToHtml} from './json-to-html.js';
@@ -202,25 +202,24 @@ const processNewsletterContent = (html, options) => { // eslint-disable-line no-
202
202
  }
203
203
  });
204
204
 
205
- const $html = cheerio.load(cleanedContent, {
206
- xml: {
207
- decodeEntities: false
208
- }
209
- });
205
+ const cleanedHTML = domUtils.processFragment(cleanedContent, (parsed) => {
206
+ parsed.$('p').forEach((el) => {
207
+ const innerHtml = domUtils.serializeChildren(el).trim();
208
+ if (!innerHtml.length || innerHtml === '<br>' || innerHtml === '<br/>') {
209
+ el.remove();
210
+ }
211
+ });
210
212
 
211
- $html('p').each((i, el) => {
212
- const innerHtml = $html(el).html().trim();
213
- if (!innerHtml.length || innerHtml === '<br>' || innerHtml === '<br/>') {
214
- $html(el).remove();
215
- }
216
- });
213
+ // :contains is a jQuery-specific selector, so filter manually
214
+ parsed.$('a').forEach((el) => {
215
+ if ((el.textContent || '').includes('Made with Letterhead')) {
216
+ el.remove();
217
+ }
218
+ });
217
219
 
218
- $html('a:contains("Made with Letterhead")').each((i, el) => {
219
- $html(el).remove();
220
+ return parsed.html().trim();
220
221
  });
221
222
 
222
- const cleanedHTML = $html.html().trim();
223
-
224
223
  return `<!--kg-card-begin: html-->${cleanedHTML}<!--kg-card-end: html-->`;
225
224
  };
226
225
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-tinynews",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/TryGhost/migrate.git",
@@ -25,9 +25,9 @@
25
25
  "@tryghost/errors": "3.0.3",
26
26
  "@tryghost/kg-default-cards": "10.2.10",
27
27
  "@tryghost/string": "0.3.1",
28
- "cheerio": "1.2.0",
29
28
  "sanitize-html": "2.17.2",
30
- "simple-dom": "1.4.0"
29
+ "simple-dom": "1.4.0",
30
+ "@tryghost/mg-utils": "0.7.0"
31
31
  },
32
32
  "scripts": {
33
33
  "dev": "echo \"Implement me!\"",