@tryghost/mg-linkfixer 0.16.1 → 0.16.3
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 +2 -2
- package/lib/LinkFixer.js +14 -9
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -191,8 +191,8 @@ Follow the instructions for the top-level repo.
|
|
|
191
191
|
|
|
192
192
|
## Test
|
|
193
193
|
|
|
194
|
-
- `pnpm
|
|
195
|
-
-
|
|
194
|
+
- `pnpm test` runs the package tests
|
|
195
|
+
- Linting and formatting are run from the repo root (`pnpm lint`, `pnpm format`)
|
|
196
196
|
|
|
197
197
|
# Copyright & License
|
|
198
198
|
|
package/lib/LinkFixer.js
CHANGED
|
@@ -14,8 +14,7 @@ const isLexicalField = field => lexicalFields.includes(field);
|
|
|
14
14
|
function mapObject(obj, fn) {
|
|
15
15
|
return Object.fromEntries(
|
|
16
16
|
Object.entries(obj).map(([key, value]) => {
|
|
17
|
-
if (typeof value === 'object' &&
|
|
18
|
-
value !== null) {
|
|
17
|
+
if (typeof value === 'object' && value !== null) {
|
|
19
18
|
return [key, mapObject(value, fn)];
|
|
20
19
|
}
|
|
21
20
|
return [key, fn(key, value)];
|
|
@@ -65,13 +64,19 @@ export default class LinkFixer {
|
|
|
65
64
|
|
|
66
65
|
const siteURLBothProtocols = `(?:${siteURLHttp}|${siteURLHttps})`;
|
|
67
66
|
|
|
68
|
-
const RegexSlugYYYYMMDD = new RegExp(
|
|
67
|
+
const RegexSlugYYYYMMDD = new RegExp(
|
|
68
|
+
`^${siteURLBothProtocols}/[a-zA-Z0-9-]+/([0-9]{4}/[0-9]{2}/[0-9]{2})/([a-zA-Z0-9-_]*)(/)?`
|
|
69
|
+
);
|
|
69
70
|
const isSlugYYYYMMDDDatedPermalink = url.match(RegexSlugYYYYMMDD);
|
|
70
71
|
|
|
71
|
-
const RegexYYYYMMDD = new RegExp(
|
|
72
|
+
const RegexYYYYMMDD = new RegExp(
|
|
73
|
+
`^${siteURLBothProtocols}/([0-9]{4}/[0-9]{2}/[0-9]{2})/([a-zA-Z0-9-_]*)(/)?`
|
|
74
|
+
);
|
|
72
75
|
const isYYYYMMDDDatedPermalink = url.match(RegexYYYYMMDD);
|
|
73
76
|
|
|
74
|
-
const RegexSlugYYYYMM = new RegExp(
|
|
77
|
+
const RegexSlugYYYYMM = new RegExp(
|
|
78
|
+
`^${siteURLBothProtocols}/[a-zA-Z0-9-]+/([0-9]{4}/[0-9]{2})/([a-zA-Z0-9-_]*)(/)?`
|
|
79
|
+
);
|
|
75
80
|
const isSlugYYYYMMDatedPermalink = url.match(RegexSlugYYYYMM);
|
|
76
81
|
|
|
77
82
|
const RegexYYYYMM = new RegExp(`^${siteURLBothProtocols}/([0-9]{4}/[0-9]{2})/([a-zA-Z0-9-_]*)(/)?`);
|
|
@@ -96,7 +101,7 @@ export default class LinkFixer {
|
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
if (data.authors) {
|
|
99
|
-
data.authors.forEach(
|
|
104
|
+
data.authors.forEach(author => {
|
|
100
105
|
this.linkMap[author.url] = `/author/${author.data.slug}/`;
|
|
101
106
|
});
|
|
102
107
|
}
|
|
@@ -107,7 +112,7 @@ export default class LinkFixer {
|
|
|
107
112
|
});
|
|
108
113
|
|
|
109
114
|
// Remove the protocol, ensuring we treat `http` and `https` sites in the same way
|
|
110
|
-
Object.keys(this.linkMap).forEach(
|
|
115
|
+
Object.keys(this.linkMap).forEach(key => {
|
|
111
116
|
let updatedURL = LinkFixer.cleanURL(key);
|
|
112
117
|
this.linkMap[updatedURL] = this.linkMap[key];
|
|
113
118
|
});
|
|
@@ -141,7 +146,7 @@ export default class LinkFixer {
|
|
|
141
146
|
}
|
|
142
147
|
|
|
143
148
|
async processHTML(html) {
|
|
144
|
-
return processFragment(html,
|
|
149
|
+
return processFragment(html, parsed => {
|
|
145
150
|
for (const el of parsed.$('a')) {
|
|
146
151
|
let href = el.getAttribute('href');
|
|
147
152
|
|
|
@@ -193,7 +198,7 @@ export default class LinkFixer {
|
|
|
193
198
|
continue;
|
|
194
199
|
}
|
|
195
200
|
|
|
196
|
-
const fixed = await processFragment(value,
|
|
201
|
+
const fixed = await processFragment(value, parsed => {
|
|
197
202
|
for (const el of parsed.$('a')) {
|
|
198
203
|
const href = el.getAttribute('href');
|
|
199
204
|
if (!href) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-linkfixer",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/migrate.git",
|
|
@@ -18,18 +18,15 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"
|
|
22
|
-
"@tryghost/
|
|
23
|
-
"@tryghost/listr-smart-renderer": "0.15.1"
|
|
21
|
+
"@tryghost/mg-json": "0.22.3",
|
|
22
|
+
"@tryghost/listr-smart-renderer": "0.15.3"
|
|
24
23
|
},
|
|
25
24
|
"dependencies": {
|
|
26
25
|
"escape-string-regexp": "5.0.0",
|
|
27
|
-
"@tryghost/mg-utils": "0.11.
|
|
26
|
+
"@tryghost/mg-utils": "0.11.3"
|
|
28
27
|
},
|
|
29
28
|
"scripts": {
|
|
30
29
|
"dev": "echo \"Implement me!\"",
|
|
31
|
-
"test": "node --test 'test/**/*.test.js'"
|
|
32
|
-
"posttest": "pnpm lint",
|
|
33
|
-
"lint": "eslint . --ext .js --cache"
|
|
30
|
+
"test": "node --test 'test/**/*.test.js'"
|
|
34
31
|
}
|
|
35
32
|
}
|