site-config-stack 0.7.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/dist/index.cjs +69 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.mjs +65 -0
- package/package.json +40 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const processShim = typeof process !== "undefined" ? process : {};
|
|
4
|
+
const envShim = processShim.env || {};
|
|
5
|
+
const envSiteConfig = {
|
|
6
|
+
_context: "env",
|
|
7
|
+
url: [
|
|
8
|
+
envShim.NUXT_PUBLIC_VERCEL_URL,
|
|
9
|
+
// vercel
|
|
10
|
+
envShim.NUXT_PUBLIC_URL,
|
|
11
|
+
// netlify
|
|
12
|
+
envShim.NUXT_PUBLIC_CF_PAGES_URL,
|
|
13
|
+
// cloudflare pages
|
|
14
|
+
envShim.NUXT_PUBLIC_SITE_URL
|
|
15
|
+
// nuxt-site-config
|
|
16
|
+
].find((k) => Boolean(k)),
|
|
17
|
+
name: envShim.NUXT_PUBLIC_SITE_NAME,
|
|
18
|
+
description: envShim.NUXT_PUBLIC_SITE_DESCRIPTION,
|
|
19
|
+
logo: envShim.NUXT_PUBLIC_SITE_IMAGE,
|
|
20
|
+
indexable: envShim.NUXT_PUBLIC_SITE_INDEXABLE || envShim.NUXT_PUBLIC_SITE_INDEX,
|
|
21
|
+
titleSeparator: envShim.NUXT_PUBLIC_SITE_TITLE_SEPARATOR,
|
|
22
|
+
trailingSlash: envShim.NUXT_PUBLIC_SITE_TRAILING_SLASH,
|
|
23
|
+
locale: envShim.NUXT_PUBLIC_SITE_LANGUAGE || envShim.NUXT_PUBLIC_SITE_LOCALE
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function createSiteConfigStack() {
|
|
27
|
+
const stack = [];
|
|
28
|
+
function push(input) {
|
|
29
|
+
if (!input._context) {
|
|
30
|
+
let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
|
|
31
|
+
if (lastFunctionName?.includes("/"))
|
|
32
|
+
lastFunctionName = "anonymous";
|
|
33
|
+
input._context = lastFunctionName;
|
|
34
|
+
}
|
|
35
|
+
stack.push(input);
|
|
36
|
+
}
|
|
37
|
+
function get() {
|
|
38
|
+
const siteConfig = {
|
|
39
|
+
_context: {}
|
|
40
|
+
};
|
|
41
|
+
for (const o in stack) {
|
|
42
|
+
for (const k in stack[o]) {
|
|
43
|
+
const key = k;
|
|
44
|
+
const val = stack[o][k];
|
|
45
|
+
if (!k.endsWith("context") && typeof val !== "undefined") {
|
|
46
|
+
siteConfig[k] = val;
|
|
47
|
+
siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return normalizeSiteConfig(siteConfig);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
push,
|
|
55
|
+
get
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function normalizeSiteConfig(config) {
|
|
60
|
+
if (typeof config.indexable !== "undefined")
|
|
61
|
+
config.indexable = String(config.indexable) !== "false";
|
|
62
|
+
if (typeof config.trailingSlash !== "undefined")
|
|
63
|
+
config.trailingSlash = String(config.trailingSlash) !== "false";
|
|
64
|
+
return config;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.createSiteConfigStack = createSiteConfigStack;
|
|
68
|
+
exports.envSiteConfig = envSiteConfig;
|
|
69
|
+
exports.normalizeSiteConfig = normalizeSiteConfig;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
interface SiteConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The canonical Site URL.
|
|
4
|
+
*
|
|
5
|
+
* @default `process.env.NUXT_PUBLIC_SITE_URL`
|
|
6
|
+
*
|
|
7
|
+
* - Build / Prerender: Inferred from CI environment (Netlify, Vercel)
|
|
8
|
+
* - SSR: Inferred from request headers
|
|
9
|
+
* - SPA: Inferred from `window.location`
|
|
10
|
+
*
|
|
11
|
+
* Used by: nuxt-simple-sitemap, nuxt-simple-robots, nuxt-schema-org, nuxt-og-image, etc.
|
|
12
|
+
*/
|
|
13
|
+
url?: string;
|
|
14
|
+
titleSeparator?: string;
|
|
15
|
+
indexable?: boolean;
|
|
16
|
+
trailingSlash?: boolean;
|
|
17
|
+
locale?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The name of the site.
|
|
20
|
+
*
|
|
21
|
+
* @default `process.env.NUXT_PUBLIC_SITE_NAME`
|
|
22
|
+
*
|
|
23
|
+
* - Build / Prerender: Inferred from CI environment (Netlify) or `package.json`
|
|
24
|
+
* - SSR:
|
|
25
|
+
*
|
|
26
|
+
* Used by: nuxt-schema-org, nuxt-seo-kit
|
|
27
|
+
*/
|
|
28
|
+
name?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The description of the site.
|
|
31
|
+
*
|
|
32
|
+
* @default `process.env.NUXT_PUBLIC_SITE_DESCRIPTION`
|
|
33
|
+
*
|
|
34
|
+
* Used by: nuxt-schema-org, nuxt-seo-kit
|
|
35
|
+
*/
|
|
36
|
+
description?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The logo of the site.
|
|
39
|
+
*
|
|
40
|
+
* @default `process.env.NUXT_PUBLIC_SITE_LOGO`
|
|
41
|
+
*
|
|
42
|
+
* Used by: nuxt-schema-org, nuxt-seo-kit
|
|
43
|
+
*/
|
|
44
|
+
logo?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The mapping of the context of each site config value being set.
|
|
47
|
+
*/
|
|
48
|
+
_context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
|
|
49
|
+
}
|
|
50
|
+
interface SiteConfigInput {
|
|
51
|
+
/**
|
|
52
|
+
* A description of the context which added the config.
|
|
53
|
+
*/
|
|
54
|
+
_context?: string;
|
|
55
|
+
url?: string;
|
|
56
|
+
name?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
logo?: string;
|
|
59
|
+
coverImage?: string;
|
|
60
|
+
titleSeparator?: string;
|
|
61
|
+
locale?: string;
|
|
62
|
+
indexable?: boolean | string;
|
|
63
|
+
trailingSlash?: boolean | string;
|
|
64
|
+
}
|
|
65
|
+
interface SiteConfigStack {
|
|
66
|
+
push: (config: SiteConfigInput) => void;
|
|
67
|
+
get: () => SiteConfig;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare const envSiteConfig: SiteConfigInput;
|
|
71
|
+
|
|
72
|
+
declare function createSiteConfigStack(): SiteConfigStack;
|
|
73
|
+
|
|
74
|
+
declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
|
|
75
|
+
|
|
76
|
+
export { SiteConfig, SiteConfigInput, SiteConfigStack, createSiteConfigStack, envSiteConfig, normalizeSiteConfig };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const processShim = typeof process !== "undefined" ? process : {};
|
|
2
|
+
const envShim = processShim.env || {};
|
|
3
|
+
const envSiteConfig = {
|
|
4
|
+
_context: "env",
|
|
5
|
+
url: [
|
|
6
|
+
envShim.NUXT_PUBLIC_VERCEL_URL,
|
|
7
|
+
// vercel
|
|
8
|
+
envShim.NUXT_PUBLIC_URL,
|
|
9
|
+
// netlify
|
|
10
|
+
envShim.NUXT_PUBLIC_CF_PAGES_URL,
|
|
11
|
+
// cloudflare pages
|
|
12
|
+
envShim.NUXT_PUBLIC_SITE_URL
|
|
13
|
+
// nuxt-site-config
|
|
14
|
+
].find((k) => Boolean(k)),
|
|
15
|
+
name: envShim.NUXT_PUBLIC_SITE_NAME,
|
|
16
|
+
description: envShim.NUXT_PUBLIC_SITE_DESCRIPTION,
|
|
17
|
+
logo: envShim.NUXT_PUBLIC_SITE_IMAGE,
|
|
18
|
+
indexable: envShim.NUXT_PUBLIC_SITE_INDEXABLE || envShim.NUXT_PUBLIC_SITE_INDEX,
|
|
19
|
+
titleSeparator: envShim.NUXT_PUBLIC_SITE_TITLE_SEPARATOR,
|
|
20
|
+
trailingSlash: envShim.NUXT_PUBLIC_SITE_TRAILING_SLASH,
|
|
21
|
+
locale: envShim.NUXT_PUBLIC_SITE_LANGUAGE || envShim.NUXT_PUBLIC_SITE_LOCALE
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function createSiteConfigStack() {
|
|
25
|
+
const stack = [];
|
|
26
|
+
function push(input) {
|
|
27
|
+
if (!input._context) {
|
|
28
|
+
let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
|
|
29
|
+
if (lastFunctionName?.includes("/"))
|
|
30
|
+
lastFunctionName = "anonymous";
|
|
31
|
+
input._context = lastFunctionName;
|
|
32
|
+
}
|
|
33
|
+
stack.push(input);
|
|
34
|
+
}
|
|
35
|
+
function get() {
|
|
36
|
+
const siteConfig = {
|
|
37
|
+
_context: {}
|
|
38
|
+
};
|
|
39
|
+
for (const o in stack) {
|
|
40
|
+
for (const k in stack[o]) {
|
|
41
|
+
const key = k;
|
|
42
|
+
const val = stack[o][k];
|
|
43
|
+
if (!k.endsWith("context") && typeof val !== "undefined") {
|
|
44
|
+
siteConfig[k] = val;
|
|
45
|
+
siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return normalizeSiteConfig(siteConfig);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
push,
|
|
53
|
+
get
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function normalizeSiteConfig(config) {
|
|
58
|
+
if (typeof config.indexable !== "undefined")
|
|
59
|
+
config.indexable = String(config.indexable) !== "false";
|
|
60
|
+
if (typeof config.trailingSlash !== "undefined")
|
|
61
|
+
config.trailingSlash = String(config.trailingSlash) !== "false";
|
|
62
|
+
return config;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { createSiteConfigStack, envSiteConfig, normalizeSiteConfig };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "site-config-stack",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.7.2",
|
|
5
|
+
"description": "Shared site configuration utilities.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"funding": "https://github.com/sponsors/harlan-zw",
|
|
8
|
+
"homepage": "https://github.com/harlan-zw/nuxt-site-config#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/harlan-zw/nuxt-site-config.git",
|
|
12
|
+
"directory": "packages/site-config"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/harlan-zw/nuxt-site-config/issues"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.cjs",
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.cjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@nuxt/kit": "^3.6.1",
|
|
31
|
+
"defu": "^6.1.2",
|
|
32
|
+
"pkg-types": "^1.0.3",
|
|
33
|
+
"ufo": "^1.1.2"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"lint": "eslint . --fix",
|
|
37
|
+
"build": "unbuild",
|
|
38
|
+
"stub": "unbuild --stub"
|
|
39
|
+
}
|
|
40
|
+
}
|