@tryghost/mg-linkfixer 0.6.2 → 0.8.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 +1 -1
- package/lib/LinkFixer.js +14 -14
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ or
|
|
|
14
14
|
|
|
15
15
|
## Develop
|
|
16
16
|
|
|
17
|
-
This is a mono repository, managed with [
|
|
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 {
|
|
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
|
-
|
|
133
|
+
return processFragment(html, (parsed) => {
|
|
134
|
+
for (const el of parsed.$('a')) {
|
|
135
|
+
let href = el.getAttribute('href');
|
|
134
136
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
if (!href) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
146
|
-
|
|
144
|
+
if (this.linkMap[updatedURL]) {
|
|
145
|
+
el.setAttribute('href', this.linkMap[updatedURL]);
|
|
146
|
+
}
|
|
147
147
|
}
|
|
148
|
-
}
|
|
149
148
|
|
|
150
|
-
|
|
149
|
+
return parsed.html();
|
|
150
|
+
});
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
async processLexical(lexical) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-linkfixer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"repository":
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/TryGhost/migrate.git",
|
|
7
|
+
"directory": "packages/mg-linkfixer"
|
|
8
|
+
},
|
|
5
9
|
"author": "Ghost Foundation",
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"main": "index.js",
|
|
@@ -9,8 +13,8 @@
|
|
|
9
13
|
"scripts": {
|
|
10
14
|
"dev": "echo \"Implement me!\"",
|
|
11
15
|
"test": "node --test 'test/**/*.test.js'",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
16
|
+
"posttest": "yarn lint",
|
|
17
|
+
"lint": "eslint . --ext .js --cache"
|
|
14
18
|
},
|
|
15
19
|
"files": [
|
|
16
20
|
"index.js",
|
|
@@ -20,13 +24,12 @@
|
|
|
20
24
|
"access": "public"
|
|
21
25
|
},
|
|
22
26
|
"devDependencies": {
|
|
23
|
-
"@tryghost/listr-smart-renderer": "0.
|
|
27
|
+
"@tryghost/listr-smart-renderer": "0.7.0",
|
|
24
28
|
"eslint": "8.57.1",
|
|
25
29
|
"listr": "0.14.3"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"@tryghost/mg-utils": "0.
|
|
29
|
-
"lodash": "4.
|
|
30
|
-
}
|
|
31
|
-
"gitHead": "dfaf02f58e6598ec4abb56a568eb1b6a65ee12f4"
|
|
32
|
+
"@tryghost/mg-utils": "0.3.0",
|
|
33
|
+
"lodash": "4.18.1"
|
|
34
|
+
}
|
|
32
35
|
}
|