site-config-stack 1.3.0 → 1.5.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.
- package/dist/index.cjs +18 -6
- package/dist/index.d.cts +17 -5
- package/dist/index.d.mts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.mjs +18 -6
- package/package.json +9 -3
package/dist/index.cjs
CHANGED
|
@@ -2,18 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
const ufo = require('ufo');
|
|
4
4
|
|
|
5
|
-
function createSiteConfigStack() {
|
|
5
|
+
function createSiteConfigStack(options) {
|
|
6
|
+
const debug = options?.debug || false;
|
|
6
7
|
const stack = [];
|
|
7
8
|
function push(input) {
|
|
8
9
|
if (!input || typeof input !== "object" || Object.keys(input).length === 0)
|
|
9
10
|
return;
|
|
10
|
-
if (!input._context) {
|
|
11
|
+
if (!input._context && debug) {
|
|
11
12
|
let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
|
|
12
13
|
if (lastFunctionName?.includes("/"))
|
|
13
14
|
lastFunctionName = "anonymous";
|
|
14
15
|
input._context = lastFunctionName;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
const entry = {};
|
|
18
|
+
for (const k in input) {
|
|
19
|
+
const val = input[k];
|
|
20
|
+
if (typeof val !== "undefined" && val !== "")
|
|
21
|
+
entry[k] = val;
|
|
22
|
+
}
|
|
23
|
+
if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
|
|
24
|
+
stack.push(entry);
|
|
17
25
|
}
|
|
18
26
|
function get() {
|
|
19
27
|
const siteConfig = {
|
|
@@ -23,7 +31,7 @@ function createSiteConfigStack() {
|
|
|
23
31
|
for (const k in stack[o]) {
|
|
24
32
|
const key = k;
|
|
25
33
|
const val = stack[o][k];
|
|
26
|
-
if (!k.startsWith("_")
|
|
34
|
+
if (!k.startsWith("_")) {
|
|
27
35
|
siteConfig[k] = val;
|
|
28
36
|
siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
|
|
29
37
|
}
|
|
@@ -45,7 +53,11 @@ function normalizeSiteConfig(config) {
|
|
|
45
53
|
config.trailingSlash = String(config.trailingSlash) !== "false";
|
|
46
54
|
if (config.url && !ufo.hasProtocol(config.url, { acceptRelative: true, strict: false }))
|
|
47
55
|
config.url = ufo.withHttps(config.url);
|
|
48
|
-
|
|
56
|
+
const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
|
|
57
|
+
const newConfig = {};
|
|
58
|
+
for (const k of keys)
|
|
59
|
+
newConfig[k] = config[k];
|
|
60
|
+
return newConfig;
|
|
49
61
|
}
|
|
50
62
|
function resolveSitePath(pathOrUrl, options) {
|
|
51
63
|
let path = pathOrUrl;
|
|
@@ -53,7 +65,7 @@ function resolveSitePath(pathOrUrl, options) {
|
|
|
53
65
|
const parsed = ufo.parseURL(pathOrUrl);
|
|
54
66
|
path = parsed.pathname;
|
|
55
67
|
}
|
|
56
|
-
const base = ufo.withLeadingSlash(options.base);
|
|
68
|
+
const base = ufo.withLeadingSlash(options.base || "/");
|
|
57
69
|
if (base !== "/" && path.startsWith(base)) {
|
|
58
70
|
path = path.slice(base.length);
|
|
59
71
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
|
|
1
3
|
interface SiteConfig {
|
|
2
4
|
/**
|
|
3
5
|
* The canonical Site URL.
|
|
@@ -22,6 +24,10 @@ interface SiteConfig {
|
|
|
22
24
|
* Whether the site is indexable by search engines.
|
|
23
25
|
*/
|
|
24
26
|
indexable: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The environment of the site. Comparable to `process.env.NODE_ENV`.
|
|
29
|
+
*/
|
|
30
|
+
env: 'production' | 'staging' | 'development' | string;
|
|
25
31
|
/**
|
|
26
32
|
* Whether the site uses trailing slash.
|
|
27
33
|
*/
|
|
@@ -68,10 +74,14 @@ interface SiteConfig {
|
|
|
68
74
|
_context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
|
|
69
75
|
[key: (string & Record<never, never>)]: any;
|
|
70
76
|
}
|
|
71
|
-
type
|
|
77
|
+
type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
|
|
78
|
+
type MaybeComputedRefEntries<T> = {
|
|
79
|
+
[key in keyof T]?: MaybeComputedRef<T[key]>;
|
|
80
|
+
};
|
|
81
|
+
type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfig>>, '_context' | 'indexable'> & {
|
|
72
82
|
_context?: string;
|
|
73
83
|
_priority?: number;
|
|
74
|
-
indexable?: string | boolean
|
|
84
|
+
indexable?: MaybeComputedRef<string | boolean>;
|
|
75
85
|
};
|
|
76
86
|
interface SiteConfigStack {
|
|
77
87
|
stack: Partial<SiteConfigInput>[];
|
|
@@ -79,16 +89,18 @@ interface SiteConfigStack {
|
|
|
79
89
|
get: () => SiteConfig;
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
declare function createSiteConfigStack(
|
|
92
|
+
declare function createSiteConfigStack(options?: {
|
|
93
|
+
debug: boolean;
|
|
94
|
+
}): SiteConfigStack;
|
|
83
95
|
|
|
84
96
|
declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
|
|
85
97
|
declare function resolveSitePath(pathOrUrl: string, options: {
|
|
86
98
|
siteUrl: string;
|
|
87
99
|
trailingSlash: boolean;
|
|
88
|
-
base
|
|
100
|
+
base?: string;
|
|
89
101
|
absolute?: boolean;
|
|
90
102
|
withBase?: boolean;
|
|
91
103
|
}): string;
|
|
92
104
|
declare function fixSlashes(trailingSlash: boolean, pathOrUrl: string): string;
|
|
93
105
|
|
|
94
|
-
export { type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
|
|
106
|
+
export { type MaybeComputedRef, type MaybeComputedRefEntries, type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
|
|
1
3
|
interface SiteConfig {
|
|
2
4
|
/**
|
|
3
5
|
* The canonical Site URL.
|
|
@@ -22,6 +24,10 @@ interface SiteConfig {
|
|
|
22
24
|
* Whether the site is indexable by search engines.
|
|
23
25
|
*/
|
|
24
26
|
indexable: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The environment of the site. Comparable to `process.env.NODE_ENV`.
|
|
29
|
+
*/
|
|
30
|
+
env: 'production' | 'staging' | 'development' | string;
|
|
25
31
|
/**
|
|
26
32
|
* Whether the site uses trailing slash.
|
|
27
33
|
*/
|
|
@@ -68,10 +74,14 @@ interface SiteConfig {
|
|
|
68
74
|
_context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
|
|
69
75
|
[key: (string & Record<never, never>)]: any;
|
|
70
76
|
}
|
|
71
|
-
type
|
|
77
|
+
type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
|
|
78
|
+
type MaybeComputedRefEntries<T> = {
|
|
79
|
+
[key in keyof T]?: MaybeComputedRef<T[key]>;
|
|
80
|
+
};
|
|
81
|
+
type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfig>>, '_context' | 'indexable'> & {
|
|
72
82
|
_context?: string;
|
|
73
83
|
_priority?: number;
|
|
74
|
-
indexable?: string | boolean
|
|
84
|
+
indexable?: MaybeComputedRef<string | boolean>;
|
|
75
85
|
};
|
|
76
86
|
interface SiteConfigStack {
|
|
77
87
|
stack: Partial<SiteConfigInput>[];
|
|
@@ -79,16 +89,18 @@ interface SiteConfigStack {
|
|
|
79
89
|
get: () => SiteConfig;
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
declare function createSiteConfigStack(
|
|
92
|
+
declare function createSiteConfigStack(options?: {
|
|
93
|
+
debug: boolean;
|
|
94
|
+
}): SiteConfigStack;
|
|
83
95
|
|
|
84
96
|
declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
|
|
85
97
|
declare function resolveSitePath(pathOrUrl: string, options: {
|
|
86
98
|
siteUrl: string;
|
|
87
99
|
trailingSlash: boolean;
|
|
88
|
-
base
|
|
100
|
+
base?: string;
|
|
89
101
|
absolute?: boolean;
|
|
90
102
|
withBase?: boolean;
|
|
91
103
|
}): string;
|
|
92
104
|
declare function fixSlashes(trailingSlash: boolean, pathOrUrl: string): string;
|
|
93
105
|
|
|
94
|
-
export { type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
|
|
106
|
+
export { type MaybeComputedRef, type MaybeComputedRefEntries, type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
|
|
1
3
|
interface SiteConfig {
|
|
2
4
|
/**
|
|
3
5
|
* The canonical Site URL.
|
|
@@ -22,6 +24,10 @@ interface SiteConfig {
|
|
|
22
24
|
* Whether the site is indexable by search engines.
|
|
23
25
|
*/
|
|
24
26
|
indexable: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The environment of the site. Comparable to `process.env.NODE_ENV`.
|
|
29
|
+
*/
|
|
30
|
+
env: 'production' | 'staging' | 'development' | string;
|
|
25
31
|
/**
|
|
26
32
|
* Whether the site uses trailing slash.
|
|
27
33
|
*/
|
|
@@ -68,10 +74,14 @@ interface SiteConfig {
|
|
|
68
74
|
_context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
|
|
69
75
|
[key: (string & Record<never, never>)]: any;
|
|
70
76
|
}
|
|
71
|
-
type
|
|
77
|
+
type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
|
|
78
|
+
type MaybeComputedRefEntries<T> = {
|
|
79
|
+
[key in keyof T]?: MaybeComputedRef<T[key]>;
|
|
80
|
+
};
|
|
81
|
+
type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfig>>, '_context' | 'indexable'> & {
|
|
72
82
|
_context?: string;
|
|
73
83
|
_priority?: number;
|
|
74
|
-
indexable?: string | boolean
|
|
84
|
+
indexable?: MaybeComputedRef<string | boolean>;
|
|
75
85
|
};
|
|
76
86
|
interface SiteConfigStack {
|
|
77
87
|
stack: Partial<SiteConfigInput>[];
|
|
@@ -79,16 +89,18 @@ interface SiteConfigStack {
|
|
|
79
89
|
get: () => SiteConfig;
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
declare function createSiteConfigStack(
|
|
92
|
+
declare function createSiteConfigStack(options?: {
|
|
93
|
+
debug: boolean;
|
|
94
|
+
}): SiteConfigStack;
|
|
83
95
|
|
|
84
96
|
declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
|
|
85
97
|
declare function resolveSitePath(pathOrUrl: string, options: {
|
|
86
98
|
siteUrl: string;
|
|
87
99
|
trailingSlash: boolean;
|
|
88
|
-
base
|
|
100
|
+
base?: string;
|
|
89
101
|
absolute?: boolean;
|
|
90
102
|
withBase?: boolean;
|
|
91
103
|
}): string;
|
|
92
104
|
declare function fixSlashes(trailingSlash: boolean, pathOrUrl: string): string;
|
|
93
105
|
|
|
94
|
-
export { type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
|
|
106
|
+
export { type MaybeComputedRef, type MaybeComputedRefEntries, type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { hasProtocol, withHttps, parseURL, withLeadingSlash, withBase, withTrailingSlash, withoutTrailingSlash } from 'ufo';
|
|
2
2
|
|
|
3
|
-
function createSiteConfigStack() {
|
|
3
|
+
function createSiteConfigStack(options) {
|
|
4
|
+
const debug = options?.debug || false;
|
|
4
5
|
const stack = [];
|
|
5
6
|
function push(input) {
|
|
6
7
|
if (!input || typeof input !== "object" || Object.keys(input).length === 0)
|
|
7
8
|
return;
|
|
8
|
-
if (!input._context) {
|
|
9
|
+
if (!input._context && debug) {
|
|
9
10
|
let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
|
|
10
11
|
if (lastFunctionName?.includes("/"))
|
|
11
12
|
lastFunctionName = "anonymous";
|
|
12
13
|
input._context = lastFunctionName;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
const entry = {};
|
|
16
|
+
for (const k in input) {
|
|
17
|
+
const val = input[k];
|
|
18
|
+
if (typeof val !== "undefined" && val !== "")
|
|
19
|
+
entry[k] = val;
|
|
20
|
+
}
|
|
21
|
+
if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
|
|
22
|
+
stack.push(entry);
|
|
15
23
|
}
|
|
16
24
|
function get() {
|
|
17
25
|
const siteConfig = {
|
|
@@ -21,7 +29,7 @@ function createSiteConfigStack() {
|
|
|
21
29
|
for (const k in stack[o]) {
|
|
22
30
|
const key = k;
|
|
23
31
|
const val = stack[o][k];
|
|
24
|
-
if (!k.startsWith("_")
|
|
32
|
+
if (!k.startsWith("_")) {
|
|
25
33
|
siteConfig[k] = val;
|
|
26
34
|
siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
|
|
27
35
|
}
|
|
@@ -43,7 +51,11 @@ function normalizeSiteConfig(config) {
|
|
|
43
51
|
config.trailingSlash = String(config.trailingSlash) !== "false";
|
|
44
52
|
if (config.url && !hasProtocol(config.url, { acceptRelative: true, strict: false }))
|
|
45
53
|
config.url = withHttps(config.url);
|
|
46
|
-
|
|
54
|
+
const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
|
|
55
|
+
const newConfig = {};
|
|
56
|
+
for (const k of keys)
|
|
57
|
+
newConfig[k] = config[k];
|
|
58
|
+
return newConfig;
|
|
47
59
|
}
|
|
48
60
|
function resolveSitePath(pathOrUrl, options) {
|
|
49
61
|
let path = pathOrUrl;
|
|
@@ -51,7 +63,7 @@ function resolveSitePath(pathOrUrl, options) {
|
|
|
51
63
|
const parsed = parseURL(pathOrUrl);
|
|
52
64
|
path = parsed.pathname;
|
|
53
65
|
}
|
|
54
|
-
const base = withLeadingSlash(options.base);
|
|
66
|
+
const base = withLeadingSlash(options.base || "/");
|
|
55
67
|
if (base !== "/" && path.startsWith(base)) {
|
|
56
68
|
path = path.slice(base.length);
|
|
57
69
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "site-config-stack",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"description": "Shared site configuration
|
|
4
|
+
"version": "1.5.0",
|
|
5
|
+
"description": "Shared site configuration utilities.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
8
8
|
"homepage": "https://github.com/harlan-zw/nuxt-site-config#readme",
|
|
@@ -26,8 +26,14 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"vue": "^3"
|
|
31
|
+
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"ufo": "^1.3.
|
|
33
|
+
"ufo": "^1.3.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"vue": "^3.3.4"
|
|
31
37
|
},
|
|
32
38
|
"scripts": {
|
|
33
39
|
"lint": "eslint . --fix",
|