@tryghost/mg-tinynews 0.3.0 → 0.5.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.
- package/README.md +7 -7
- package/lib/mapper.js +15 -16
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ To use this package in your own project:
|
|
|
17
17
|
|
|
18
18
|
or
|
|
19
19
|
|
|
20
|
-
`
|
|
20
|
+
`pnpm add @tryghost/mg-tinynews`
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
@@ -80,26 +80,26 @@ This will get all posts, pages, newsletters, and authors.
|
|
|
80
80
|
|
|
81
81
|
## Develop
|
|
82
82
|
|
|
83
|
-
This is a mono repository, managed with [Nx](https://nx.dev/) and
|
|
83
|
+
This is a mono repository, managed with [Nx](https://nx.dev/) and pnpm workspaces.
|
|
84
84
|
|
|
85
85
|
Follow the instructions for the top-level repo.
|
|
86
86
|
1. `git clone` this repo & `cd` into it as usual
|
|
87
|
-
2. Run `
|
|
87
|
+
2. Run `pnpm install` to install top-level dependencies.
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
## Run
|
|
91
91
|
|
|
92
|
-
To run a local development copy, `cd` into this directory, and use `
|
|
92
|
+
To run a local development copy, `cd` into this directory, and use `pnpm dev` instead of `migrate` like so:
|
|
93
93
|
|
|
94
94
|
```sh
|
|
95
|
-
|
|
95
|
+
pnpm dev tinynews [options]
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
## Test
|
|
100
100
|
|
|
101
|
-
- `
|
|
102
|
-
- `
|
|
101
|
+
- `pnpm lint` run just eslint
|
|
102
|
+
- `pnpm test` run lint and tests
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
# Copyright & License
|
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
|
|
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
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.5.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.6.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"dev": "echo \"Implement me!\"",
|