@reldens/cms 0.36.0 → 0.37.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,54 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - CMS - AssetTransformer
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { sc } = require('@reldens/utils');
|
|
8
|
-
|
|
9
|
-
class AssetTransformer
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
async transform(template, domain, req, systemVariables)
|
|
13
|
-
{
|
|
14
|
-
if(!template){
|
|
15
|
-
return template;
|
|
16
|
-
}
|
|
17
|
-
let currentRequest = sc.get(systemVariables, 'currentRequest', {});
|
|
18
|
-
let assetPattern = /\[asset\(([^)]+)\)\]/g;
|
|
19
|
-
let matches = [...template.matchAll(assetPattern)];
|
|
20
|
-
for(let i = matches.length - 1; i >= 0; i--){
|
|
21
|
-
let match = matches[i];
|
|
22
|
-
let assetPath = match[1].replace(/['"]/g, '');
|
|
23
|
-
let absoluteUrl = this.buildAssetUrl(assetPath, currentRequest);
|
|
24
|
-
template = template.substring(0, match.index) +
|
|
25
|
-
absoluteUrl +
|
|
26
|
-
template.substring(match.index + match[0].length);
|
|
27
|
-
}
|
|
28
|
-
return template;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
buildAssetUrl(assetPath, currentRequest)
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
let normalizedPath = assetPath.startsWith('/') ? assetPath : '/'+assetPath;
|
|
46
|
-
if(assetUrl){
|
|
47
|
-
return assetUrl+normalizedPath;
|
|
48
|
-
}
|
|
49
|
-
return publicUrl+'/assets'+normalizedPath;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
module.exports.AssetTransformer = AssetTransformer;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - CMS - AssetTransformer
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { sc } = require('@reldens/utils');
|
|
8
|
+
|
|
9
|
+
class AssetTransformer
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
async transform(template, domain, req, systemVariables)
|
|
13
|
+
{
|
|
14
|
+
if(!template){
|
|
15
|
+
return template;
|
|
16
|
+
}
|
|
17
|
+
let currentRequest = sc.get(systemVariables, 'currentRequest', {});
|
|
18
|
+
let assetPattern = /\[asset\(([^)]+)\)\]/g;
|
|
19
|
+
let matches = [...template.matchAll(assetPattern)];
|
|
20
|
+
for(let i = matches.length - 1; i >= 0; i--){
|
|
21
|
+
let match = matches[i];
|
|
22
|
+
let assetPath = match[1].replace(/['"]/g, '');
|
|
23
|
+
let absoluteUrl = this.buildAssetUrl(assetPath, currentRequest);
|
|
24
|
+
template = template.substring(0, match.index) +
|
|
25
|
+
absoluteUrl +
|
|
26
|
+
template.substring(match.index + match[0].length);
|
|
27
|
+
}
|
|
28
|
+
return template;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
buildAssetUrl(assetPath, currentRequest)
|
|
32
|
+
{
|
|
33
|
+
if(!assetPath || assetPath.startsWith('http')){
|
|
34
|
+
return assetPath;
|
|
35
|
+
}
|
|
36
|
+
return sc.get(currentRequest, 'assetUrl', '')+'/assets'+(assetPath.startsWith('/') ? assetPath : '/'+assetPath);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports.AssetTransformer = AssetTransformer;
|