@tryghost/mg-linkfixer 0.6.2 → 0.7.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 CHANGED
@@ -14,7 +14,7 @@ or
14
14
 
15
15
  ## Develop
16
16
 
17
- This is a mono repository, managed with [lerna](https://lernajs.io/).
17
+ This is a mono repository, managed with [Nx](https://nx.dev/) and yarn workspaces.
18
18
 
19
19
  Follow the instructions for the top-level repo.
20
20
  1. `git clone` this repo & `cd` into it as usual
package/lib/LinkFixer.js CHANGED
@@ -2,7 +2,7 @@ import {join} from 'node:path';
2
2
  import _ from 'lodash';
3
3
  import {domUtils} from '@tryghost/mg-utils';
4
4
 
5
- const {parseFragment} = domUtils;
5
+ const {processFragment} = domUtils;
6
6
 
7
7
  // @TODO: expand this list
8
8
  const htmlFields = ['html'];
@@ -130,24 +130,24 @@ export default class LinkFixer {
130
130
  }
131
131
 
132
132
  async processHTML(html) {
133
- const parsed = parseFragment(html);
133
+ return processFragment(html, (parsed) => {
134
+ for (const el of parsed.$('a')) {
135
+ let href = el.getAttribute('href');
134
136
 
135
- for (const el of parsed.$('a')) {
136
- let href = el.getAttribute('href');
137
+ if (!href) {
138
+ continue;
139
+ }
137
140
 
138
- if (!href) {
139
- continue;
140
- }
141
-
142
- // Clean the URL, matching the links stored in the linkMap
143
- let updatedURL = this.cleanURL(href);
141
+ // Clean the URL, matching the links stored in the linkMap
142
+ let updatedURL = this.cleanURL(href);
144
143
 
145
- if (this.linkMap[updatedURL]) {
146
- el.setAttribute('href', this.linkMap[updatedURL]);
144
+ if (this.linkMap[updatedURL]) {
145
+ el.setAttribute('href', this.linkMap[updatedURL]);
146
+ }
147
147
  }
148
- }
149
148
 
150
- return parsed.html();
149
+ return parsed.html();
150
+ });
151
151
  }
152
152
 
153
153
  async processLexical(lexical) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-linkfixer",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-linkfixer",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -9,8 +9,8 @@
9
9
  "scripts": {
10
10
  "dev": "echo \"Implement me!\"",
11
11
  "test": "node --test 'test/**/*.test.js'",
12
- "lint": "eslint . --ext .js --cache",
13
- "posttest": "yarn lint"
12
+ "posttest": "yarn lint",
13
+ "lint": "eslint . --ext .js --cache"
14
14
  },
15
15
  "files": [
16
16
  "index.js",
@@ -20,13 +20,12 @@
20
20
  "access": "public"
21
21
  },
22
22
  "devDependencies": {
23
- "@tryghost/listr-smart-renderer": "0.5.24",
23
+ "@tryghost/listr-smart-renderer": "0.6.0",
24
24
  "eslint": "8.57.1",
25
25
  "listr": "0.14.3"
26
26
  },
27
27
  "dependencies": {
28
- "@tryghost/mg-utils": "0.1.2",
28
+ "@tryghost/mg-utils": "0.2.0",
29
29
  "lodash": "4.17.23"
30
- },
31
- "gitHead": "dfaf02f58e6598ec4abb56a568eb1b6a65ee12f4"
30
+ }
32
31
  }