@tryghost/mg-linkfixer 0.5.31 → 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.
- package/lib/LinkFixer.js +10 -14
- 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
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
let href =
|
|
135
|
+
for (const el of parsed.$('a')) {
|
|
136
|
+
let href = el.getAttribute('href');
|
|
140
137
|
|
|
141
138
|
if (!href) {
|
|
142
|
-
|
|
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
|
-
|
|
146
|
+
el.setAttribute('href', this.linkMap[updatedURL]);
|
|
150
147
|
}
|
|
151
|
-
}
|
|
148
|
+
}
|
|
152
149
|
|
|
153
|
-
|
|
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.
|
|
3
|
+
"version": "0.6.0",
|
|
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": "
|
|
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.
|
|
24
|
-
"eslint": "8.57.
|
|
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
|
-
"
|
|
28
|
+
"@tryghost/mg-utils": "0.1.0",
|
|
31
29
|
"lodash": "4.17.23"
|
|
32
30
|
},
|
|
33
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "e1680568191322d738c188f03298910aa3622735"
|
|
34
32
|
}
|