You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/build-pages/resolve-vars.js
+41-9Lines changed: 41 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
* @param {string} [params.varsPath] - Path to the file containing the variables.
6
6
* @param {object} [params.resolveVars] - Any variables you want passed to the reolveFunction.
7
7
* @param {string} [params.key='default'] - The key to extract from the imported module. Default: 'default'
8
-
* @returns {Promise<object|function>} - Returns the resolved variables. If the imported variable is a function, it executes and returns its result. Otherwise, it returns the variable directly.
8
+
* @returns {Promise<object>} - Returns the resolved variables. If the imported variable is a function, it executes and returns its result. Otherwise, it returns the variable directly.
9
9
*/
10
10
exportasyncfunctionresolveVars({
11
11
varsPath,
@@ -31,12 +31,44 @@ export async function resolveVars ({
31
31
}
32
32
}
33
33
34
+
/**
35
+
* @import { PageData } from './page-data.js'
36
+
*/
37
+
38
+
/**
39
+
* Resolve and call a global.data.js file with the initialized PageData array.
thrownewError('global.data default export function must return an object')
59
+
}elseif(isObject(maybeGlobalData)){
60
+
returnmaybeGlobalData
61
+
}else{
62
+
return{}
63
+
}
64
+
}
65
+
34
66
/**
35
67
* Resolve variables by importing them from a specified path.
36
68
*
37
69
* @param {object} params
38
70
* @param {string} [params.varsPath] - Path to the file containing the variables.
39
-
* @returns {Promise<function|null>} - Returns the resolved variables. If the imported variable is a function, it executes and returns its result. Otherwise, it returns the variable directly.
71
+
* @returns {Promise<null>}
40
72
*/
41
73
exportasyncfunctionresolvePostVars({
42
74
varsPath,
@@ -47,14 +79,14 @@ export async function resolvePostVars ({
47
79
constmaybePostVars=imported.postVars
48
80
49
81
if(maybePostVars){
50
-
if(isFunction(maybePostVars)){
51
-
returnmaybePostVars
52
-
}else{
53
-
thrownewError('postVars must export a function')
54
-
}
55
-
}else{
56
-
returnnull
82
+
thrownewError(
83
+
`postVars is no longer supported (found in ${varsPath}). `+
84
+
'Move data aggregation to a global.data.js file instead. '+
0 commit comments