@laioutr/app-hygraph 1.6.0 → 1.7.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 +1 -1
- package/dist/runtime/server/generated/graphql.d.ts +2 -0
- package/dist/runtime/server/hygraph-utils/mediaMapper.d.ts +2 -2
- package/dist/runtime/server/hygraph-utils/mediaMapper.js +32 -14
- package/dist/runtime/server/orchestr/blog/blogPost.resolver.js +6 -2
- package/dist/runtime/server/queries/blog.d.ts +2 -2
- package/dist/runtime/server/queries/blog.js +2 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Media } from '@laioutr-core/core-types/common';
|
|
2
2
|
import type { HygraphAsset } from '../types/hygraph.js';
|
|
3
3
|
/** Remove the file extension from a file name. */
|
|
4
4
|
export declare const stripFileExtension: (fileName: string) => string;
|
|
@@ -7,4 +7,4 @@ export declare const filenameToAlt: (fileName: string) => string;
|
|
|
7
7
|
/**
|
|
8
8
|
* Map a Hygraph asset to a Media object.
|
|
9
9
|
*/
|
|
10
|
-
export declare const mapHygraphMedia: (asset: HygraphAsset) =>
|
|
10
|
+
export declare const mapHygraphMedia: (asset: HygraphAsset) => Media;
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
export const stripFileExtension = (fileName) => fileName.replace(/\.[^.]+$/, "");
|
|
2
2
|
export const filenameToAlt = (fileName) => stripFileExtension(fileName).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").replace(/^\w/, (c) => c.toUpperCase()).trim();
|
|
3
|
-
export const mapHygraphMedia = (asset) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
export const mapHygraphMedia = (asset) => {
|
|
4
|
+
const mimeType = typeof asset.mimeType === "string" ? asset.mimeType : "";
|
|
5
|
+
if (mimeType.startsWith("video/")) {
|
|
6
|
+
return {
|
|
7
|
+
type: "video",
|
|
8
|
+
sources: [
|
|
9
|
+
{
|
|
10
|
+
provider: "hygraph",
|
|
11
|
+
src: asset.url,
|
|
12
|
+
width: asset.width ?? void 0,
|
|
13
|
+
height: asset.height ?? void 0,
|
|
14
|
+
format: mimeType.slice("video/".length)
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
alt: filenameToAlt(asset.fileName)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
type: "image",
|
|
22
|
+
sources: [
|
|
23
|
+
{
|
|
24
|
+
// SVGs are returned as none so Nuxt Image won't turn them into PNG file links.
|
|
25
|
+
provider: mimeType === "image/svg+xml" ? "none" : "hygraph",
|
|
26
|
+
src: asset.url,
|
|
27
|
+
width: asset.width ?? void 0,
|
|
28
|
+
height: asset.height ?? void 0,
|
|
29
|
+
responsive: "static"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
alt: filenameToAlt(asset.fileName)
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BlogPostBase, BlogPostContent, BlogPostExcerpt, BlogPostMedia } from "@laioutr-core/canonical-types/entity/blog-post";
|
|
1
|
+
import { BlogPostBase, BlogPostContent, BlogPostExcerpt, BlogPostMedia, BlogPostSeo } from "@laioutr-core/canonical-types/entity/blog-post";
|
|
2
2
|
import { blogPostsToken } from "../../const/passthroughTokens.js";
|
|
3
3
|
import { mapHygraphMedia } from "../../hygraph-utils/mediaMapper.js";
|
|
4
4
|
import { defineHygraph } from "../../middleware/defineHygraph.js";
|
|
5
5
|
export default defineHygraph.componentResolver({
|
|
6
6
|
entityType: "BlogPost",
|
|
7
7
|
label: "Blog Post",
|
|
8
|
-
provides: [BlogPostBase, BlogPostExcerpt, BlogPostContent, BlogPostMedia],
|
|
8
|
+
provides: [BlogPostBase, BlogPostExcerpt, BlogPostContent, BlogPostMedia, BlogPostSeo],
|
|
9
9
|
resolve: async ({ passthrough, $entity }) => {
|
|
10
10
|
const posts = passthrough.require(blogPostsToken);
|
|
11
11
|
return {
|
|
@@ -29,6 +29,10 @@ export default defineHygraph.componentResolver({
|
|
|
29
29
|
},
|
|
30
30
|
media: {
|
|
31
31
|
image: post.image ? mapHygraphMedia(post.image) : { type: "image", sources: [{ provider: "none", src: "/placeholders/1x1.svg" }] }
|
|
32
|
+
},
|
|
33
|
+
seo: {
|
|
34
|
+
title: post.metaTitle ?? void 0,
|
|
35
|
+
description: post.metaDescription ?? void 0
|
|
32
36
|
}
|
|
33
37
|
})
|
|
34
38
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const BLOGS_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n }\n\n query Blogs($skip: Int, $first: Int, $collectionId: ID, $locales: [Locale!]!) {\n blogs(\n skip: $skip\n first: $first\n orderBy: createdAt_DESC\n where: { blogCollection: { id: $collectionId } }\n locales: $locales\n ) {\n ...Blog\n }\n blogsConnection(where: { blogCollection: { id: $collectionId } }, locales: $locales) {\n aggregate {\n count\n }\n }\n }\n";
|
|
2
|
-
export declare const BLOG_POST_BY_SLUG_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n }\n\n query BlogPostBySlug($slug: String!, $locales: [Locale!]!) {\n blog(where: { slug: $slug }, locales: $locales) {\n ...Blog\n }\n }\n";
|
|
1
|
+
export declare const BLOGS_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n metaTitle\n metaDescription\n }\n\n query Blogs($skip: Int, $first: Int, $collectionId: ID, $locales: [Locale!]!) {\n blogs(\n skip: $skip\n first: $first\n orderBy: createdAt_DESC\n where: { blogCollection: { id: $collectionId } }\n locales: $locales\n ) {\n ...Blog\n }\n blogsConnection(where: { blogCollection: { id: $collectionId } }, locales: $locales) {\n aggregate {\n count\n }\n }\n }\n";
|
|
2
|
+
export declare const BLOG_POST_BY_SLUG_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n metaTitle\n metaDescription\n }\n\n query BlogPostBySlug($slug: String!, $locales: [Locale!]!) {\n blog(where: { slug: $slug }, locales: $locales) {\n ...Blog\n }\n }\n";
|
|
3
3
|
export declare const BLOG_COLLECTION_BY_SLUG_QUERY = "\n #graphql\n query BlogCollectionBySlug($slug: String!, $locales: [Locale!]!) {\n blogCollection(where: { slug: $slug }, locales: $locales) {\n id\n slug\n title\n }\n }\n";
|
|
4
4
|
export declare const BLOG_COLLECTIONS_QUERY = "\n #graphql\n query BlogCollections($locales: [Locale!]!) {\n blogCollections(locales: $locales) {\n slug\n title\n }\n }\n";
|