From 9e53d418960e98d4957294ee98849b5a635c7c7c Mon Sep 17 00:00:00 2001 From: mosesintech Date: Mon, 29 Apr 2024 15:32:22 -0500 Subject: [PATCH 1/2] feat(site): add blogroll page template --- src/templates/archives/default.tsx | 128 ++++++++++++++++++++- src/types/post.ts | 176 +++++++++++++++++++++++++++++ 2 files changed, 300 insertions(+), 4 deletions(-) create mode 100644 src/types/post.ts diff --git a/src/templates/archives/default.tsx b/src/templates/archives/default.tsx index 7ff4530..c4cf1e2 100644 --- a/src/templates/archives/default.tsx +++ b/src/templates/archives/default.tsx @@ -1,7 +1,127 @@ -export default function PostArchiveTemplate() { +import Link from "next/link"; +import Image from "next/image"; +import { + type TemplateProps, + stripWpUrl, + swapWpUrl, + getFeaturedImage, +} from "@nextwp/core"; +import type { ArchivePageData } from "@nextwp/core/src/api/get-page-data/get-archive-page"; +import type { Post } from "~/types/post"; +import { Badge } from "~/components/ui/badge"; +import Edges from "~/components/layout/edges"; +// import { ArchivePagination } from "~/components/template-parts/archive-pagination"; +import { parseHtml } from "~/lib/utils"; + +interface BlogArchiveData extends Omit { + items?: Post[]; +} + +interface BlogArchive extends Omit { + data: BlogArchiveData; +} + +export default function PostArchiveTemplate(props: BlogArchive) { + const { + data: { + items, + page, + // prevPage, + // nextPage, + // totalItems, + // totalPages, + // currentPage, + }, + } = props; + return ( - <> -

PostArchiveTemplate

- + +

{parseHtml(page?.title?.rendered)}

+
+ {items?.map((post: Post) => { + const featuredImage = getFeaturedImage(post); + + return ( +
+
+ {featuredImage?.url ? ( + + ) : null} + +
+
+
+
+ + + {post?._embedded?.["wp:term"]?.map((tax) => { + return tax?.map((term, index) => { + return ( + + {term.name} + + ); + }); + })} +
+
+

+ + + {post.title.rendered} + +

+
+
+
+ + +
+

+ + {post?._embedded?.author?.[0].name} +

+

{post.author.role}

+
+ +
+
+
+ ); + })} +
+ + {/*
+ +
*/} +
); } diff --git a/src/types/post.ts b/src/types/post.ts new file mode 100644 index 0000000..e63e1ad --- /dev/null +++ b/src/types/post.ts @@ -0,0 +1,176 @@ +export interface Post { + /** + * ACF field data + */ + acf: unknown; + /** + * The ID for the author of the post. + */ + author: number; + /** + * The terms assigned to the post in the category taxonomy. + */ + categories: number[]; + /** + * Whether or not comments are open on the post. + */ + comment_status: "open" | "closed"; + /** + * The content for the post. + */ + content: { + /** + * Version of the content block format used by the post. + */ + block_version: number; + /** + * Whether the content is protected with a password. + */ + protected: boolean; + /** + * Content for the post, as it exists in the database. + */ + raw: string; + /** + * HTML content for the post, transformed for display. + */ + rendered: string; + }; + /** + * The date the post was published, in the site's timezone. + */ + date: string | null; + /** + * The date the post was published, as GMT. + */ + date_gmt: string | null; + /** + * The excerpt for the post. + */ + excerpt: { + /** + * Whether the excerpt is protected with a password. + */ + protected: boolean; + /** + * Excerpt for the post, as it exists in the database. + */ + raw: string; + /** + * HTML excerpt for the post, transformed for display. + */ + rendered: string; + }; + /** + * The ID of the featured media for the post. + */ + featured_media: number; + /** + * The format for the post. + */ + format: + | "standard" + | "aside" + | "chat" + | "gallery" + | "link" + | "image" + | "quote" + | "status" + | "video" + | "audio"; + /** + * Slug automatically generated from the post title. + */ + generated_slug: string; + /** + * The globally unique identifier for the post. + */ + guid: { + /** + * GUID for the post, as it exists in the database. + */ + raw: string; + /** + * GUID for the post, transformed for display. + */ + rendered: string; + }; + /** + * Unique identifier for the post. + */ + id: number; + /** + * URL to the post. + */ + link: string; + /** + * Meta fields. + */ + meta: { + footnotes: string; + }; + /** + * The date the post was last modified, in the site's timezone. + */ + modified: string; + /** + * The date the post was last modified, as GMT. + */ + modified_gmt: string; + /** + * A password to protect access to the content and excerpt. + */ + password: string; + /** + * Permalink template for the post. + */ + permalink_template: string; + /** + * Whether or not the post can be pinged. + */ + ping_status: "open" | "closed"; + /** + * An alphanumeric identifier for the post unique to its type. + */ + slug: string; + /** + * A named status for the post. + */ + status: + | "publish" + | "future" + | "draft" + | "pending" + | "private" + | "acf-disabled"; + /** + * Whether or not the post should be treated as sticky. + */ + sticky: boolean; + /** + * The terms assigned to the post in the post_tag taxonomy. + */ + tags: number[]; + /** + * The theme file to use to display the post. + */ + template: string; + /** + * The title for the post. + */ + title: { + /** + * Title for the post, as it exists in the database. + */ + raw: string; + /** + * HTML title for the post, transformed for display. + */ + rendered: string; + }; + /** + * Type of post. + */ + type: string; +} From e0f0e04ac42b9e90a80d03b9e1b29193f175ac10 Mon Sep 17 00:00:00 2001 From: mosesintech Date: Mon, 29 Apr 2024 15:43:35 -0500 Subject: [PATCH 2/2] fix(site): comment out errors in blogroll --- src/templates/archives/default.tsx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/templates/archives/default.tsx b/src/templates/archives/default.tsx index c4cf1e2..b28c854 100644 --- a/src/templates/archives/default.tsx +++ b/src/templates/archives/default.tsx @@ -2,19 +2,25 @@ import Link from "next/link"; import Image from "next/image"; import { type TemplateProps, - stripWpUrl, + // stripWpUrl, swapWpUrl, getFeaturedImage, + type WpPage, } from "@nextwp/core"; -import type { ArchivePageData } from "@nextwp/core/src/api/get-page-data/get-archive-page"; import type { Post } from "~/types/post"; -import { Badge } from "~/components/ui/badge"; +// import { Badge } from "~/components/ui/badge"; import Edges from "~/components/layout/edges"; // import { ArchivePagination } from "~/components/template-parts/archive-pagination"; import { parseHtml } from "~/lib/utils"; -interface BlogArchiveData extends Omit { +interface BlogArchiveData { items?: Post[]; + page?: WpPage | undefined; + prevPage?: string | undefined; + nextPage?: string | undefined; + totalPages?: number | undefined; + totalItems?: number | undefined; + currentPage?: number | undefined; } interface BlogArchive extends Omit { @@ -36,7 +42,7 @@ export default function PostArchiveTemplate(props: BlogArchive) { return ( -

{parseHtml(page?.title?.rendered)}

+

{parseHtml(`${page?.title?.rendered}`)}

{items?.map((post: Post) => { const featuredImage = getFeaturedImage(post); @@ -60,11 +66,11 @@ export default function PostArchiveTemplate(props: BlogArchive) {
-

@@ -89,7 +95,7 @@ export default function PostArchiveTemplate(props: BlogArchive) { />

- + {/*

{post.author.role}

- + */}