diff --git a/components/agility-components/FeaturedPost.tsx b/components/agility-components/FeaturedPost.tsx index 3ee8f3f..2405707 100644 --- a/components/agility-components/FeaturedPost.tsx +++ b/components/agility-components/FeaturedPost.tsx @@ -1,65 +1,77 @@ import Link from "next/link" -import {DateTime} from "luxon" -import {stripHtml} from "string-strip-html" -import {AgilityPic, Module, ContentItem, AgilityImage, UnloadedModuleProps} from "@agility/nextjs" -import {IPost} from "../../lib/types/IPost" -import {getContentItem} from "lib/cms/getContentItem" +import { DateTime } from "luxon" +import { stripHtml } from "string-strip-html" +import { + AgilityPic, + Module, + ContentItem, + AgilityImage, + UnloadedModuleProps, +} from "@agility/nextjs" +import { IPost } from "../../lib/types/IPost" +import { getContentItem } from "lib/cms/getContentItem" interface IFeaturedPostModule { - featuredPost?: { - contentid: number - } + featuredPost?: { + contentid: number + } } -const FeaturedPost = async ({module, languageCode}: UnloadedModuleProps) => { - const {fields, contentID} = await getContentItem({ - contentID: module.contentid, - languageCode, - contentLinkDepth: 0, - }) +const FeaturedPost = async ({ module, languageCode }: UnloadedModuleProps) => { + const { fields, contentID } = await getContentItem({ + contentID: module.contentid, + languageCode, + contentLinkDepth: 0, + }) - if (fields.featuredPost?.contentid === undefined) return null + if (fields.featuredPost?.contentid === undefined) return null - const featuredPost: ContentItem = await getContentItem({ - contentID: fields.featuredPost?.contentid, - languageCode, - contentLinkDepth: 1, - }) + const featuredPost: ContentItem = await getContentItem({ + contentID: fields.featuredPost?.contentid, + languageCode, + contentLinkDepth: 1, + }) - let dateStr = "" - let contentStr = "" - if (featuredPost) { - // convert date to str in a way that will work on the server and client with the same value - dateStr = DateTime.fromJSDate(new Date(featuredPost.fields.date)).toFormat("LLL. dd, yyyy") - //strip out html tags to build an excerpt - contentStr = stripHtml(featuredPost?.fields.content || "").result - if (contentStr.length > 200) contentStr = `${contentStr.substring(0, 200)}...` - } + let dateStr = "" + let contentStr = "" + if (featuredPost) { + // convert date to str in a way that will work on the server and client with the same value + dateStr = DateTime.fromJSDate(new Date(featuredPost.fields.date)).toFormat( + "LLL. dd, yyyy" + ) + //strip out html tags to build an excerpt + contentStr = stripHtml(featuredPost?.fields.content || "").result + if (contentStr.length > 200) + contentStr = `${contentStr.substring(0, 200)}...` + } - if (!featuredPost) return null + if (!featuredPost) return null - return ( -
-
-
- -
- {/* Agility Pic - outputs a tag */} - + return ( +
+
+
+ +
+ {/* Agility Pic - outputs a tag */} + - {/* + {/* OR you can use AgilityImage - A wrapper for next/image - MUST be used from the component with "use client" to test out the following code, - uncomment the component below @@ -67,7 +79,7 @@ const FeaturedPost = async ({module, languageCode}: UnloadedModuleProps) => { - add AgilityImage to the "@agility/nextjs" import at the top of the file */} - {/* { sizes="(max-width: 640px) 100vw, 50vw" /> */} -
- -
-
- -
- {featuredPost.fields.category.fields.title} -
-
-
{dateStr}
-

- {featuredPost.fields.title} -

-

{contentStr}

- -
-
-
- ) +
+ +
+
+ +
+ {featuredPost.fields.category?.fields.title} +
+
+
+ {dateStr} +
+

+ {featuredPost.fields.title} +

+

+ {contentStr} +

+ +
+
+
+ ) } export default FeaturedPost