@gluhar/app 2.5.0 → 2.5.1
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/CHANGELOG.md +11 -0
- package/dist/module.json +1 -1
- package/dist/runtime/composables/useSanityPage.d.ts +20 -0
- package/dist/runtime/composables/useSanityPage.js +59 -0
- package/package.json +2 -2
- package/dist/runtime/composables/usePages.d.ts +0 -0
- package/dist/runtime/composables/usePages.js +0 -63
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.5.1](https://github.com/gluharry/gluhar/compare/@gluhar/app@2.5.0...@gluhar/app@2.5.1) (2025-01-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 🩹 Fixes
|
|
10
|
+
|
|
11
|
+
- UsePages to useSanityPage ([23cc055](https://github.com/gluharry/gluhar/commit/23cc05564abb443bf76278d9e4de253bd820b07b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [2.5.0](https://github.com/gluharry/gluhar/compare/@gluhar/app@2.4.6...@gluhar/app@2.5.0) (2025-01-28)
|
|
7
18
|
|
|
8
19
|
|
package/dist/module.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AsyncDataRequestStatus } from "#app";
|
|
2
|
+
import type { KeysOf, PickFrom } from "#app/composables/asyncData";
|
|
3
|
+
import type { SanityPage } from "@gluhar/sanity/types";
|
|
4
|
+
interface Page extends SanityPage {
|
|
5
|
+
_type: "page";
|
|
6
|
+
}
|
|
7
|
+
type PageTypeKeys = "page" | string;
|
|
8
|
+
type PageInterfaces = Record<PageTypeKeys, Page | SanityPage>;
|
|
9
|
+
type PageTypes<PI extends PageInterfaces> = Record<keyof PI, {
|
|
10
|
+
query: string;
|
|
11
|
+
slug: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const useSanityPage: <PI extends PageInterfaces = {
|
|
15
|
+
page: Page;
|
|
16
|
+
}, PT extends PageTypes<PI> = PageTypes<PI>>(types?: PT, slug?: string | string[]) => Promise<{
|
|
17
|
+
page: import("vue").Ref<PickFrom<PI[Extract<keyof PT, string>], KeysOf<PI[Extract<keyof PT, string>]>> | null, PickFrom<PI[Extract<keyof PT, string>], KeysOf<PI[Extract<keyof PT, string>]>> | null> | import("vue").Ref<Page | null, Page | null> | undefined;
|
|
18
|
+
status: import("vue").Ref<AsyncDataRequestStatus, AsyncDataRequestStatus> | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCanonicalUrl,
|
|
3
|
+
groq,
|
|
4
|
+
useHead,
|
|
5
|
+
useRoute,
|
|
6
|
+
useSanityQueryWithPreview
|
|
7
|
+
} from "#imports";
|
|
8
|
+
import { imageWithAsset, linkWithPage } from "@gluhar/sanity/query";
|
|
9
|
+
export const useSanityPage = async (types, slug) => {
|
|
10
|
+
const route = useRoute();
|
|
11
|
+
const s = slug ? slug : route.params.slug;
|
|
12
|
+
const sl = Array.isArray(s) ? s : [s];
|
|
13
|
+
let page, status;
|
|
14
|
+
if (types && sl.length > 1) {
|
|
15
|
+
for (const type in types) {
|
|
16
|
+
const options = types[type];
|
|
17
|
+
if (sl[0] === options.slug) {
|
|
18
|
+
const query = groq`
|
|
19
|
+
*[_type == "${type}" && slug.current == "${sl[1]}"]{
|
|
20
|
+
${options.query}
|
|
21
|
+
}[0]
|
|
22
|
+
`;
|
|
23
|
+
const q = await useSanityQueryWithPreview(query);
|
|
24
|
+
page = q.data;
|
|
25
|
+
status = q.status;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
const pageQuery = groq`
|
|
30
|
+
...,
|
|
31
|
+
content[]{
|
|
32
|
+
...,
|
|
33
|
+
_ref != null => @-> {
|
|
34
|
+
...,
|
|
35
|
+
button{ ${linkWithPage} },
|
|
36
|
+
thumbnail{ ${imageWithAsset} },
|
|
37
|
+
image{ ${imageWithAsset} },
|
|
38
|
+
images[]{ ${imageWithAsset} },
|
|
39
|
+
bckg{ ${imageWithAsset} },
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
const query = groq`
|
|
44
|
+
*[_type == "page" && slug.current == "${sl[0] ? sl?.join("/") : "/"}"]{
|
|
45
|
+
${types?.page?.query ?? pageQuery}
|
|
46
|
+
}[0]
|
|
47
|
+
`;
|
|
48
|
+
const q = await useSanityQueryWithPreview(query);
|
|
49
|
+
if (q.data.value) q.data.value._type = "page";
|
|
50
|
+
page = q.data;
|
|
51
|
+
status = q.status;
|
|
52
|
+
}
|
|
53
|
+
useHead({
|
|
54
|
+
link: [
|
|
55
|
+
{ rel: "canonical", href: getCanonicalUrl(page?.value) }
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
return { page, status };
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gluhar/app",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Gluhar main package. This combines and configures @gluhar/theme, @gluhar/i18n, @gluhar/sanity and @gluhar/core into one main package. Provides numerous components, composables, utils and types.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"nuxt": "^3.13.1",
|
|
59
59
|
"vitest": "^2.0.5"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "03d4d85e4be0a9d1220c16e2c1029c3aefedda01"
|
|
62
62
|
}
|
|
File without changes
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getCanonicalUrl,
|
|
3
|
-
groq,
|
|
4
|
-
useHead,
|
|
5
|
-
useRoute,
|
|
6
|
-
useSanityQueryWithPreview
|
|
7
|
-
} from "#imports";
|
|
8
|
-
import { imageWithAsset, linkWithPage } from "@gluhar/sanity/query";
|
|
9
|
-
export const usePages = (types) => {
|
|
10
|
-
const route = useRoute();
|
|
11
|
-
const getSanityPage = async (slug) => {
|
|
12
|
-
const s = slug ? slug : route.params.slug;
|
|
13
|
-
const sl = Array.isArray(s) ? s : [s];
|
|
14
|
-
if (types && sl.length > 1) {
|
|
15
|
-
for (const type in types) {
|
|
16
|
-
const options = types[type];
|
|
17
|
-
if (sl[0] === options.slug) {
|
|
18
|
-
const query2 = groq`
|
|
19
|
-
*[_type == "${type}" && slug.current == "${sl[1]}"]{
|
|
20
|
-
${options.query}
|
|
21
|
-
}[0]
|
|
22
|
-
`;
|
|
23
|
-
const { data: data2, status: status2 } = await useSanityQueryWithPreview(query2);
|
|
24
|
-
useHead({
|
|
25
|
-
link: [
|
|
26
|
-
{
|
|
27
|
-
rel: "canonical",
|
|
28
|
-
href: getCanonicalUrl(data2.value)
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
});
|
|
32
|
-
return { data: data2, status: status2 };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const pageQuery = groq`
|
|
37
|
-
...,
|
|
38
|
-
content[]{
|
|
39
|
-
...,
|
|
40
|
-
_ref != null => @-> {
|
|
41
|
-
...,
|
|
42
|
-
button{ ${linkWithPage} },
|
|
43
|
-
thumbnail{ ${imageWithAsset} },
|
|
44
|
-
image{ ${imageWithAsset} },
|
|
45
|
-
images[]{ ${imageWithAsset} },
|
|
46
|
-
bckg{ ${imageWithAsset} },
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
`;
|
|
50
|
-
const query = groq`
|
|
51
|
-
*[_type == "page" && slug.current == "${sl[0] ? sl?.join("/") : "/"}"]{
|
|
52
|
-
${types?.page?.query ?? pageQuery}
|
|
53
|
-
}[0]
|
|
54
|
-
`;
|
|
55
|
-
const { data, status } = await useSanityQueryWithPreview(query);
|
|
56
|
-
if (data.value) data.value._type = "page";
|
|
57
|
-
useHead({
|
|
58
|
-
link: [{ rel: "canonical", href: getCanonicalUrl(data.value) }]
|
|
59
|
-
});
|
|
60
|
-
return { page: data, status };
|
|
61
|
-
};
|
|
62
|
-
return { getSanityPage };
|
|
63
|
-
};
|