@tryghost/url-utils 4.2.0 → 4.3.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.
@@ -1,5 +1,5 @@
1
1
  function lexicalTransform(serializedLexical, siteUrl, transformFunction, itemPath, _options = {}) {
2
- const defaultOptions = {assetsOnly: false, secure: false};
2
+ const defaultOptions = {assetsOnly: false, secure: false, nodes: [], transformMap: {}};
3
3
  const options = Object.assign({}, defaultOptions, _options, {siteUrl, itemPath});
4
4
 
5
5
  if (!serializedLexical) {
@@ -14,11 +14,21 @@ function lexicalTransform(serializedLexical, siteUrl, transformFunction, itemPat
14
14
  return serializedLexical;
15
15
  }
16
16
 
17
- // any lexical links will be a child object with a `url` attribute,
18
- // recursively walk the tree transforming any `.url`s
17
+ const nodeMap = new Map();
18
+ options.nodes.forEach(node => node.urlTransformMap && nodeMap.set(node.getType(), node.urlTransformMap));
19
+
19
20
  const transformChildren = function (children) {
20
21
  for (const child of children) {
21
- if (child.url) {
22
+ // cards (nodes) have a `type` attribute in their node data
23
+ if (child.type && nodeMap.has(child.type)) {
24
+ Object.entries(nodeMap.get(child.type)).forEach(([property, transform]) => {
25
+ if (child[property]) {
26
+ child[property] = options.transformMap[options.transformType][transform](child[property]);
27
+ }
28
+ });
29
+ } else if (child.url) {
30
+ // any lexical links will be a child object with a `url` attribute,
31
+ // recursively walk the tree transforming any `.url`s
22
32
  child.url = transformFunction(child.url, siteUrl, itemPath, options);
23
33
  }
24
34
 
@@ -2,7 +2,7 @@ const absoluteToRelative = require('./absolute-to-relative');
2
2
  const lexicalTransform = require('./_lexical-transform');
3
3
 
4
4
  function lexicalAbsoluteToRelative(serializedLexical, siteUrl, _options = {}) {
5
- const defaultOptions = {assetsOnly: false, secure: false, cardTransformers: []};
5
+ const defaultOptions = {assetsOnly: false, secure: false, nodes: [], transformMap: {}};
6
6
  const overrideOptions = {siteUrl, transformType: 'absoluteToRelative'};
7
7
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
8
8
 
@@ -2,7 +2,7 @@ const absoluteToTransformReady = require('./absolute-to-transform-ready');
2
2
  const lexicalTransform = require('./_lexical-transform');
3
3
 
4
4
  function lexicalAbsoluteToRelative(serializedLexical, siteUrl, _options = {}) {
5
- const defaultOptions = {assetsOnly: false, secure: false, cardTransformers: []};
5
+ const defaultOptions = {assetsOnly: false, secure: false, nodes: [], transformMap: {}};
6
6
  const overrideOptions = {siteUrl, transformType: 'toTransformReady'};
7
7
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
8
8
 
@@ -2,7 +2,7 @@ const relativeToAbsolute = require('./relative-to-absolute');
2
2
  const lexicalTransform = require('./_lexical-transform');
3
3
 
4
4
  function lexicalRelativeToAbsolute(serializedLexical, siteUrl, itemPath, _options = {}) {
5
- const defaultOptions = {assetsOnly: false, secure: false, cardTransformers: []};
5
+ const defaultOptions = {assetsOnly: false, secure: false, nodes: [], transformMap: {}};
6
6
  const overrideOptions = {siteUrl, itemPath, transformType: 'relativeToAbsolute'};
7
7
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
8
8
 
@@ -2,7 +2,7 @@ const relativeToTransformReady = require('./relative-to-transform-ready');
2
2
  const lexicalTransform = require('./_lexical-transform');
3
3
 
4
4
  function lexicalRelativeToTransformReady(serializedLexical, siteUrl, itemPath, _options = {}) {
5
- const defaultOptions = {assetsOnly: false, secure: false, cardTransformers: []};
5
+ const defaultOptions = {assetsOnly: false, secure: false, nodes: [], transformMap: {}};
6
6
  const overrideOptions = {siteUrl, transformType: 'toTransformReady'};
7
7
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/url-utils",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "repository": "https://github.com/TryGhost/SDK/tree/master/packages/url-utils",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -19,12 +19,12 @@
19
19
  "access": "public"
20
20
  },
21
21
  "devDependencies": {
22
- "@tryghost/config-url-helpers": "^1.0.3",
22
+ "@tryghost/config-url-helpers": "^1.0.4",
23
23
  "c8": "7.12.0",
24
- "mocha": "10.0.0",
24
+ "mocha": "10.1.0",
25
25
  "rewire": "6.0.0",
26
26
  "should": "13.2.3",
27
- "sinon": "14.0.0"
27
+ "sinon": "15.0.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "cheerio": "^0.22.0",
@@ -34,5 +34,5 @@
34
34
  "remark-footnotes": "^1.0.0",
35
35
  "unist-util-visit": "^2.0.0"
36
36
  },
37
- "gitHead": "7e8faa4260a758bca46ef7f6ff7ed0bd7ec21a13"
37
+ "gitHead": "bc7ef4154981d09195c25acd6eda0531b1cffa32"
38
38
  }