@tryghost/mg-linkfixer 0.5.31 → 0.6.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/LinkFixer.js +10 -14
  2. package/package.json +6 -8
package/lib/LinkFixer.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import {join} from 'node:path';
2
2
  import _ from 'lodash';
3
- import * as cheerio from 'cheerio';
3
+ import {domUtils} from '@tryghost/mg-utils';
4
+
5
+ const {parseFragment} = domUtils;
4
6
 
5
7
  // @TODO: expand this list
6
8
  const htmlFields = ['html'];
@@ -128,30 +130,24 @@ export default class LinkFixer {
128
130
  }
129
131
 
130
132
  async processHTML(html) {
131
- let $ = cheerio.load(html, {
132
- xml: {
133
- decodeEntities: false,
134
- scriptingEnabled: false
135
- }
136
- }, false); // This `false` is `isDocument`. If `true`, <html>, <head>, and <body> elements are introduced
133
+ const parsed = parseFragment(html);
137
134
 
138
- let links = $('a').map(async (i, el) => {
139
- let href = $(el).attr('href');
135
+ for (const el of parsed.$('a')) {
136
+ let href = el.getAttribute('href');
140
137
 
141
138
  if (!href) {
142
- return;
139
+ continue;
143
140
  }
144
141
 
145
142
  // Clean the URL, matching the links stored in the linkMap
146
143
  let updatedURL = this.cleanURL(href);
147
144
 
148
145
  if (this.linkMap[updatedURL]) {
149
- $(el).attr('href', this.linkMap[updatedURL]);
146
+ el.setAttribute('href', this.linkMap[updatedURL]);
150
147
  }
151
- }).get();
148
+ }
152
149
 
153
- await Promise.all(links);
154
- return $.html();
150
+ return parsed.html();
155
151
  }
156
152
 
157
153
  async processLexical(lexical) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-linkfixer",
3
- "version": "0.5.31",
3
+ "version": "0.6.1",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-linkfixer",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@
8
8
  "type": "module",
9
9
  "scripts": {
10
10
  "dev": "echo \"Implement me!\"",
11
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
11
+ "test": "node --test 'test/**/*.test.js'",
12
12
  "lint": "eslint . --ext .js --cache",
13
13
  "posttest": "yarn lint"
14
14
  },
@@ -20,15 +20,13 @@
20
20
  "access": "public"
21
21
  },
22
22
  "devDependencies": {
23
- "@tryghost/listr-smart-renderer": "0.5.23",
24
- "eslint": "8.57.0",
25
- "jest": "30.2.0",
26
- "jest-extended": "7.0.0",
23
+ "@tryghost/listr-smart-renderer": "0.5.24",
24
+ "eslint": "8.57.1",
27
25
  "listr": "0.14.3"
28
26
  },
29
27
  "dependencies": {
30
- "cheerio": "1.2.0",
28
+ "@tryghost/mg-utils": "0.1.1",
31
29
  "lodash": "4.17.23"
32
30
  },
33
- "gitHead": "ac9a868976ef5963df7fc2426af9e298bd5d8666"
31
+ "gitHead": "5fc4fe1f51b76c1b4040c0093abb931a9c593e85"
34
32
  }