nuxt-site-config 0.7.5 → 0.8.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/module.json +1 -1
- package/dist/module.mjs +3 -2
- package/dist/runtime/component/SiteLink.vue +11 -21
- package/dist/runtime/composables/useSiteConfig.d.ts +2 -1
- package/dist/runtime/composables/utils.d.ts +9 -5
- package/dist/runtime/composables/utils.mjs +25 -21
- package/dist/runtime/nitro/composables/useSiteConfig.d.ts +2 -1
- package/dist/runtime/nitro/composables/utils.d.ts +4 -0
- package/dist/runtime/nitro/composables/utils.mjs +17 -0
- package/dist/runtime/nitro/middleware/init.mjs +2 -3
- package/dist/runtime/plugins/siteConfig.mjs +4 -0
- package/package.json +3 -3
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addImports, addComponent, addPlugin, addServerHandler } from '@nuxt/kit';
|
|
2
|
-
import { updateSiteConfig, useSiteConfig, assertSiteConfig } from 'nuxt-site-config-kit';
|
|
2
|
+
import { initSiteConfig, updateSiteConfig, useSiteConfig, assertSiteConfig } from 'nuxt-site-config-kit';
|
|
3
3
|
|
|
4
4
|
const module = defineNuxtModule({
|
|
5
5
|
meta: {
|
|
@@ -19,6 +19,7 @@ const module = defineNuxtModule({
|
|
|
19
19
|
name: c
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
+
await initSiteConfig();
|
|
22
23
|
nuxt.hook("modules:done", async () => {
|
|
23
24
|
await updateSiteConfig({
|
|
24
25
|
_context: "nuxt:config:site",
|
|
@@ -33,7 +34,7 @@ const module = defineNuxtModule({
|
|
|
33
34
|
await assertSiteConfig("prerender");
|
|
34
35
|
});
|
|
35
36
|
});
|
|
36
|
-
const linkComposables = ["
|
|
37
|
+
const linkComposables = ["createSitePathResolver", "withSiteTrailingSlash", "withSiteUrl"];
|
|
37
38
|
linkComposables.forEach((c) => {
|
|
38
39
|
addImports({
|
|
39
40
|
from: resolve("./runtime/composables/utils"),
|
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
// we need to intercept the `to` property and make sure that we have the right trailing slash
|
|
3
|
-
import {
|
|
3
|
+
import { createSitePathResolver, toRefs } from '#imports'
|
|
4
4
|
|
|
5
|
-
const props = defineProps
|
|
6
|
-
to:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
to: string
|
|
7
|
+
withBase?: boolean
|
|
8
|
+
absolute?: boolean
|
|
9
|
+
}>()
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
// make props refs
|
|
12
|
+
const propRefs = toRefs(props)
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
// only for relative links
|
|
16
|
-
if (props.to !== '/' && props.to.startsWith('/'))
|
|
17
|
-
return linkResolver(props.to)
|
|
18
|
-
return props.to
|
|
19
|
-
})
|
|
14
|
+
const linkResolver = createSitePathResolver({ withBase: propRefs.withBase, absolute: propRefs.absolute })
|
|
20
15
|
|
|
21
|
-
const
|
|
22
|
-
return {
|
|
23
|
-
...props,
|
|
24
|
-
to: to.value,
|
|
25
|
-
}
|
|
26
|
-
})
|
|
16
|
+
const to = linkResolver(propRefs.to)
|
|
27
17
|
</script>
|
|
28
18
|
|
|
29
19
|
<template>
|
|
30
|
-
<NuxtLink
|
|
20
|
+
<NuxtLink :to="to">
|
|
31
21
|
<slot />
|
|
32
22
|
</NuxtLink>
|
|
33
23
|
</template>
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NuxtSiteConfig } from '../../types';
|
|
2
|
+
export declare function useSiteConfig(): NuxtSiteConfig;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}): (path: string) =>
|
|
1
|
+
import type { MaybeRef } from '@vue/reactivity';
|
|
2
|
+
export declare function createSitePathResolver(options?: {
|
|
3
|
+
absolute?: MaybeRef<boolean>;
|
|
4
|
+
withBase?: MaybeRef<boolean>;
|
|
5
|
+
}): (path: MaybeRef<string>) => any;
|
|
6
|
+
export declare function withSiteTrailingSlash(path: MaybeRef<string>): any;
|
|
7
|
+
export declare function withSiteUrl(path: MaybeRef<string>, options?: {
|
|
8
|
+
withBase?: boolean;
|
|
9
|
+
}): any;
|
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { computed, useSiteConfig } from "#imports";
|
|
3
|
-
function
|
|
4
|
-
|
|
1
|
+
import { fixSlashes, resolveSitePath } from "site-config-stack";
|
|
2
|
+
import { computed, unref, useRuntimeConfig, useSiteConfig } from "#imports";
|
|
3
|
+
export function createSitePathResolver(options = {}) {
|
|
4
|
+
const siteConfig = useSiteConfig();
|
|
5
|
+
const nuxtBase = useRuntimeConfig().app.baseURL || "/";
|
|
6
|
+
return (path) => {
|
|
7
|
+
return computed(() => resolveSitePath(unref(path), {
|
|
8
|
+
absolute: unref(options.absolute),
|
|
9
|
+
withBase: unref(options.withBase),
|
|
10
|
+
siteUrl: siteConfig.url,
|
|
11
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
12
|
+
base: nuxtBase
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
5
15
|
}
|
|
6
|
-
export function
|
|
16
|
+
export function withSiteTrailingSlash(path) {
|
|
7
17
|
const siteConfig = useSiteConfig();
|
|
8
18
|
return computed(() => {
|
|
9
|
-
|
|
10
|
-
return fixSlashes(siteConfig.trailingSlash, path);
|
|
11
|
-
return path;
|
|
19
|
+
return fixSlashes(siteConfig.trailingSlash, unref(path));
|
|
12
20
|
});
|
|
13
21
|
}
|
|
14
|
-
export function
|
|
22
|
+
export function withSiteUrl(path, options = {}) {
|
|
15
23
|
const siteConfig = useSiteConfig();
|
|
16
|
-
const
|
|
24
|
+
const base = useRuntimeConfig().app.baseURL || "/";
|
|
17
25
|
return computed(() => {
|
|
18
|
-
return
|
|
26
|
+
return resolveSitePath(unref(path), {
|
|
27
|
+
absolute: true,
|
|
28
|
+
siteUrl: siteConfig.url,
|
|
29
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
30
|
+
base,
|
|
31
|
+
withBase: options.withBase
|
|
32
|
+
});
|
|
19
33
|
});
|
|
20
34
|
}
|
|
21
|
-
export function createInternalLinkResolver(options = {}) {
|
|
22
|
-
const siteConfig = useSiteConfig();
|
|
23
|
-
return (path) => {
|
|
24
|
-
if (typeof siteConfig.trailingSlash === "boolean")
|
|
25
|
-
path = fixSlashes(siteConfig.trailingSlash, path);
|
|
26
|
-
if (!options.absolute)
|
|
27
|
-
return path;
|
|
28
|
-
return withBase(path, siteConfig.url || "/");
|
|
29
|
-
};
|
|
30
|
-
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fixSlashes, resolveSitePath } from "site-config-stack";
|
|
2
|
+
import { useRuntimeConfig, useSiteConfig } from "#imports";
|
|
3
|
+
export function withSiteTrailingSlash(path) {
|
|
4
|
+
const siteConfig = useSiteConfig();
|
|
5
|
+
return fixSlashes(siteConfig.trailingSlash, path);
|
|
6
|
+
}
|
|
7
|
+
export function withSiteUrl(path, options = {}) {
|
|
8
|
+
const siteConfig = useSiteConfig();
|
|
9
|
+
const base = useRuntimeConfig().app.baseURL || "/";
|
|
10
|
+
return resolveSitePath(path, {
|
|
11
|
+
absolute: true,
|
|
12
|
+
siteUrl: siteConfig.url,
|
|
13
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
14
|
+
base,
|
|
15
|
+
withBase: options.withBase
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { joinURL } from "ufo";
|
|
2
1
|
import { eventHandler, updateSiteConfig, useAppConfig, useNitroOrigin, useRuntimeConfig } from "#imports";
|
|
3
2
|
export default eventHandler((e) => {
|
|
4
3
|
if (!e.context.siteConfig) {
|
|
5
4
|
const appConfig = useAppConfig();
|
|
6
|
-
const { public: publicRuntimeConfig
|
|
5
|
+
const { public: publicRuntimeConfig } = useRuntimeConfig();
|
|
7
6
|
updateSiteConfig(e, {
|
|
8
7
|
_context: "nitro:init",
|
|
9
|
-
url:
|
|
8
|
+
url: useNitroOrigin(e)
|
|
10
9
|
});
|
|
11
10
|
updateSiteConfig(e, publicRuntimeConfig.site);
|
|
12
11
|
if (appConfig.site) {
|
|
@@ -15,6 +15,10 @@ export default defineNuxtPlugin({
|
|
|
15
15
|
if (!siteConfigStack)
|
|
16
16
|
siteConfigStack = createSiteConfigStack();
|
|
17
17
|
if (process.client) {
|
|
18
|
+
siteConfigStack.push({
|
|
19
|
+
_context: "window",
|
|
20
|
+
url: window.location.origin
|
|
21
|
+
});
|
|
18
22
|
const state = useState("site-config");
|
|
19
23
|
if (state)
|
|
20
24
|
siteConfigStack.push(state.value);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-site-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"packageManager": "pnpm@8.6.5",
|
|
6
6
|
"description": "Shared site configuration for Nuxt 3 modules.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@nuxt/kit": "3.6.1",
|
|
31
31
|
"ufo": "^1.1.2",
|
|
32
|
-
"nuxt-site-config-kit": "0.
|
|
33
|
-
"site-config-stack": "0.
|
|
32
|
+
"nuxt-site-config-kit": "0.8.0",
|
|
33
|
+
"site-config-stack": "0.8.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "nuxt-module-build --stub && nuxt-module-build prepare && nuxt-module-build",
|