@tryghost/url-utils 5.1.0 → 5.1.2
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/utils/absolute-to-relative.js +1 -1
- package/lib/utils/absolute-to-transform-ready.js +1 -1
- package/lib/utils/html-relative-to-absolute.js +35 -3
- package/lib/utils/html-relative-to-transform-ready.js +35 -3
- package/lib/utils/html-transform.d.ts +2 -0
- package/lib/utils/html-transform.js +15 -2
- package/lib/utils/lexical-transform.js +1 -0
- package/lib/utils/markdown-transform.js +3 -0
- package/lib/utils/relative-to-absolute.js +1 -1
- package/lib/utils/strip-subdirectory-from-path.js +1 -1
- package/package.json +4 -5
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const html_transform_1 =
|
|
39
|
+
const html_transform_1 = __importStar(require("./html-transform"));
|
|
7
40
|
const relative_to_absolute_1 = __importDefault(require("./relative-to-absolute"));
|
|
8
41
|
function htmlRelativeToAbsolute(html = '', siteUrl, itemPath, _options = {}) {
|
|
9
42
|
const defaultOptions = { assetsOnly: false, secure: false };
|
|
10
43
|
const options = Object.assign({}, defaultOptions, _options || {});
|
|
11
|
-
|
|
12
|
-
options.earlyExitMatchStr = 'href=|src=|srcset=';
|
|
44
|
+
options.earlyExitMatchStr = html_transform_1.earlyExitMatchStr;
|
|
13
45
|
if (options.assetsOnly) {
|
|
14
46
|
options.earlyExitMatchStr = options.staticImageUrlPrefix;
|
|
15
47
|
}
|
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const html_transform_1 =
|
|
39
|
+
const html_transform_1 = __importStar(require("./html-transform"));
|
|
7
40
|
const relative_to_transform_ready_1 = __importDefault(require("./relative-to-transform-ready"));
|
|
8
41
|
const htmlRelativeToTransformReady = function (html = '', root, itemPath, _options) {
|
|
9
42
|
// itemPath is optional, if it's an object may be the options param instead
|
|
@@ -23,8 +56,7 @@ const htmlRelativeToTransformReady = function (html = '', root, itemPath, _optio
|
|
|
23
56
|
secure: false
|
|
24
57
|
};
|
|
25
58
|
const options = Object.assign({}, defaultOptions, finalOptions, overrideOptions);
|
|
26
|
-
|
|
27
|
-
options.earlyExitMatchStr = 'href=|src=|srcset=';
|
|
59
|
+
options.earlyExitMatchStr = html_transform_1.earlyExitMatchStr;
|
|
28
60
|
if (options.assetsOnly) {
|
|
29
61
|
options.earlyExitMatchStr = options.staticImageUrlPrefix;
|
|
30
62
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { HtmlTransformOptionsInput, UrlTransformFunction } from './types';
|
|
2
|
+
export declare const transformAttributes: string[];
|
|
3
|
+
export declare const earlyExitMatchStr: string;
|
|
2
4
|
declare function htmlTransform(html: string | undefined, siteUrl: string, transformFunction: UrlTransformFunction, itemPath: string | null, _options?: HtmlTransformOptionsInput): string;
|
|
3
5
|
export default htmlTransform;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.earlyExitMatchStr = exports.transformAttributes = void 0;
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
3
5
|
const cheerio = require('cheerio');
|
|
6
|
+
exports.transformAttributes = [
|
|
7
|
+
'href',
|
|
8
|
+
'src',
|
|
9
|
+
'srcset',
|
|
10
|
+
'style',
|
|
11
|
+
'data-kg-background-image',
|
|
12
|
+
'data-kg-custom-thumbnail',
|
|
13
|
+
'data-kg-thumbnail'
|
|
14
|
+
];
|
|
15
|
+
exports.earlyExitMatchStr = exports.transformAttributes
|
|
16
|
+
.map(attr => `${attr}=`)
|
|
17
|
+
.join('|');
|
|
4
18
|
function escapeRegExp(string) {
|
|
5
19
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
6
20
|
}
|
|
@@ -36,8 +50,7 @@ function htmlTransform(html = '', siteUrl, transformFunction, itemPath, _options
|
|
|
36
50
|
}
|
|
37
51
|
replacements[key].push(replacement);
|
|
38
52
|
}
|
|
39
|
-
|
|
40
|
-
['href', 'src', 'srcset', 'style'].forEach((attributeName) => {
|
|
53
|
+
exports.transformAttributes.forEach((attributeName) => {
|
|
41
54
|
htmlContent('[' + attributeName + ']').each((ix, el) => {
|
|
42
55
|
// ignore <stream> elems and html inside of <code> elements
|
|
43
56
|
const elementName = 'name' in el ? el.name : null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
3
4
|
const _ = require('lodash');
|
|
4
5
|
function lexicalTransform(serializedLexical, siteUrl, transformFunction, itemPath, _options = {}) {
|
|
5
6
|
const defaultOptions = { assetsOnly: false, secure: false, nodes: [], transformMap: {} };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
3
4
|
let remark;
|
|
4
5
|
const footnotes = require('remark-footnotes');
|
|
5
6
|
const visit = require('unist-util-visit');
|
|
7
|
+
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
6
8
|
function replaceLast(find, replace, str) {
|
|
7
9
|
const lastIndex = str.lastIndexOf(find);
|
|
8
10
|
if (lastIndex === -1) {
|
|
@@ -20,6 +22,7 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
|
|
|
20
22
|
}
|
|
21
23
|
const replacements = [];
|
|
22
24
|
if (!remark) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
23
26
|
remark = require('remark');
|
|
24
27
|
}
|
|
25
28
|
if (!remark) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/url-utils",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/SDK.git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@tryghost/config-url-helpers": "^1.0.
|
|
29
|
+
"@tryghost/config-url-helpers": "^1.0.20",
|
|
30
30
|
"@types/cheerio": "^0.22.31",
|
|
31
31
|
"@types/lodash": "^4.14.202",
|
|
32
32
|
"@types/node": "^20.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"mocha": "11.7.5",
|
|
35
35
|
"rewire": "9.0.1",
|
|
36
36
|
"should": "13.2.3",
|
|
37
|
-
"sinon": "21.0.
|
|
37
|
+
"sinon": "21.0.1",
|
|
38
38
|
"typescript": "5.9.3"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
@@ -45,6 +45,5 @@
|
|
|
45
45
|
"remark": "11.0.2",
|
|
46
46
|
"remark-footnotes": "1.0.0",
|
|
47
47
|
"unist-util-visit": "^2.0.0"
|
|
48
|
-
}
|
|
49
|
-
"gitHead": "a97d783ddb64ae80592ec03468b221a4ec37948a"
|
|
48
|
+
}
|
|
50
49
|
}
|