Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ontent-cloud-sdk into PCC-1729-update-the-article-page-to-match-the-new-designs-including-author-and-tags
  • Loading branch information
kevinstubbs committed Jan 2, 2025
2 parents a861dbd + b3859a4 commit dff8ed9
Show file tree
Hide file tree
Showing 46 changed files with 346 additions and 205 deletions.
2 changes: 1 addition & 1 deletion local_testing/testpages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@pantheon-systems/pcc-react-sample-library": "workspace:*",
"next": "^14.2.10",
"next": "^14.2.15",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@pantheon-systems/pcc-sdk-core": "workspace:*",
"axios": "^1.7.5",
"axios": "^1.7.6",
"bluebird": "^3.7.2",
"boxen": "^7.1.1",
"chalk": "^5.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"eslint": "^8.57.0",
"eslint-config-pcc-custom": "workspace:*",
"jest": "29.5.0",
"next": "^14.2.10",
"next": "^14.2.15",
"octokit": "^3.2.1",
"ora": "^6.3.1",
"react": "18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"unplugin-vue": "^4.5.2",
"vite": "^5.1.8",
"vite": "^5.2.14",
"vue": "3.4.27",
"vue-3": "npm:vue@^3.4.27"
},
Expand Down
214 changes: 114 additions & 100 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { serverSmartComponentMap } from "../../../../components/smart-components

export const pantheonAPIOptions: PantheonAPIOptions = {
resolvePath: (article) => `/articles/${article.slug || article.id}`,
getSiteId: () => process.env.PCC_SITE_ID,
getSiteId: () => process.env.PCC_SITE_ID as string,
smartComponentMap: serverSmartComponentMap,
componentPreviewPath: (componentName) =>
`/component-preview/${componentName}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@ import queryString from "query-string";
import { pantheonAPIOptions } from "../../api/pantheoncloud/[...command]/api-options";
import { ClientsideArticleView } from "./clientside-articleview";

export const ArticleView = async ({ params, searchParams }) => {
const { article, grant } = await getServersideArticle(params, searchParams);
export interface ArticleViewProps {
params: { uri: string };
searchParams: {
publishingLevel: "PRODUCTION" | "REALTIME";
pccGrant: string | undefined;
};
}

export const ArticleView = async ({
params,
searchParams,
}: ArticleViewProps) => {
const { article, grant } = await getServersideArticle({
params,
searchParams,
});

return <ClientsideArticleView article={article} grant={grant} />;
return <ClientsideArticleView article={article} grant={grant || undefined} />;
};

export async function getServersideArticle(params, searchParams) {
export async function getServersideArticle({
params,
searchParams,
}: ArticleViewProps) {
const { uri } = params;
const { publishingLevel, pccGrant, ...query } = searchParams;

Expand All @@ -20,7 +37,8 @@ export async function getServersideArticle(params, searchParams) {

const article = await PCCConvenienceFunctions.getArticleBySlugOrId(
slugOrId,
publishingLevel?.toString().toUpperCase() || "PRODUCTION",
(publishingLevel?.toString().toUpperCase() as "PRODUCTION" | "REALTIME") ||
"PRODUCTION",
);

if (!article) {
Expand All @@ -29,7 +47,8 @@ export async function getServersideArticle(params, searchParams) {

if (
article.slug?.trim().length &&
article.slug.toLowerCase() !== slugOrId?.trim().toLowerCase()
article.slug.toLowerCase() !== slugOrId?.trim().toLowerCase() &&
pantheonAPIOptions.resolvePath != null
) {
// If the article was accessed by the id rather than the slug - then redirect to the canonical
// link (mostly for SEO purposes than anything else).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ updateConfig({
});

export const ClientsideArticleView = ({
grant,
article,
grant,
}: {
grant: string;
article: Article;
grant?: string | undefined;
}) => {
return (
<PantheonProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { Suspense } from "react";
import Layout from "../../../components/layout";
import { SkeletonArticleView } from "../../../components/skeleton-article-view";
import { getSeoMetadata } from "../../../lib/utils";
import { ArticleView, getServersideArticle } from "./article-view";
import {
ArticleView,
ArticleViewProps,
getServersideArticle,
} from "./article-view";

export default async function ArticlePage({ params, searchParams }) {
export default async function ArticlePage({
params,
searchParams,
}: ArticleViewProps) {
return (
<Layout>
<div className="prose mx-4 mt-16 text-black sm:mx-6 md:mx-auto">
Expand All @@ -16,8 +23,11 @@ export default async function ArticlePage({ params, searchParams }) {
);
}

export async function generateMetadata({ params, searchParams }) {
const { article } = await getServersideArticle(params, searchParams);
export async function generateMetadata({
params,
searchParams,
}: ArticleViewProps) {
const { article } = await getServersideArticle({ params, searchParams });

return getSeoMetadata(article);
}
4 changes: 2 additions & 2 deletions starters/nextjs-starter-approuter-ts/app/articles/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import ArticleList from "../../components/article-list";
import Layout from "../../components/layout";
import { PAGE_SIZE } from "../../constants";

async function fetchNextPages(cursor: string) {
async function fetchNextPages(cursor?: string | null | undefined) {
"use server";
const { data, cursor: newCursor } =
await PCCConvenienceFunctions.getPaginatedArticles({
pageSize: PAGE_SIZE,
cursor,
cursor: cursor || undefined,
});
return {
data,
Expand Down
17 changes: 12 additions & 5 deletions starters/nextjs-starter-approuter-ts/app/authors/[author]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import ArticleList from "../../../components/article-list";
import Layout from "../../../components/layout";
import { PAGE_SIZE } from "../../../constants";

function fetchNextPages(author?: string) {
return async (cursor: string) => {
function fetchNextPages(author?: string | null | undefined) {
return async (cursor?: string | null | undefined) => {
"use server";
const { data, cursor: newCursor } =
await PCCConvenienceFunctions.getPaginatedArticles({
Expand All @@ -24,7 +24,7 @@ function fetchNextPages(author?: string) {
: {
author,
},
cursor,
cursor: cursor || undefined,
});

return {
Expand All @@ -34,7 +34,11 @@ function fetchNextPages(author?: string) {
};
}

export default async function ArticlesListTemplate({ params }) {
export default async function ArticlesListTemplate({
params,
}: {
params: { author: string };
}) {
const author = params.author ? decodeURIComponent(params.author) : undefined;

const {
Expand Down Expand Up @@ -66,7 +70,10 @@ export default async function ArticlesListTemplate({ params }) {
totalCount={totalCount}
fetcher={fetchNextPages(author)}
additionalHeader={
<div className="border-base-300 mb-14 border-b-[1px] pb-7" data-testid="author-header">
<div
className="border-base-300 mb-14 border-b-[1px] pb-7"
data-testid="author-header"
>
<div className="flex flex-row gap-x-6">
<div>
<Image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function generateStaticParams() {

return publishedArticles.flatMap((article) => {
const params = [{ uri: article.id }];
if (article.metadata.slug) {
if (article.metadata?.slug) {
params.push({ uri: String(article.metadata.slug) });
}
return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export const metadata: Metadata = {
description: "Example of using SSG and ISR",
};

async function fetchNextPages(cursor: string) {
async function fetchNextPages(cursor?: string | null | undefined) {
"use server";
const { data, cursor: newCursor } =
await PCCConvenienceFunctions.getPaginatedArticles({
pageSize: PAGE_SIZE,
cursor,
cursor: cursor || undefined,
});

return {
Expand Down
3 changes: 2 additions & 1 deletion starters/nextjs-starter-approuter-ts/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Poppins } from "next/font/google";
// import Script from "next/script";

import "../styles/globals.css";
import { PropsWithChildren } from "react";

const poppins = Poppins({
subsets: ["latin"],
weight: ["400", "500", "700"],
});

function MyApp({ children }) {
function MyApp({ children }: PropsWithChildren) {
return (
<html>
<head>
Expand Down
16 changes: 11 additions & 5 deletions starters/nextjs-starter-approuter-ts/app/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import { PCCConvenienceFunctions } from "@pantheon-systems/pcc-react-sdk/server"
import Layout from "../../components/layout";
import SearchResults from "./search-results";

export default async function SearchPage({ searchParams }) {
interface Props {
searchParams: { q?: string | null | undefined };
}

export default async function SearchPage({ searchParams }: Props) {
const searchResults = await PCCConvenienceFunctions.getAllArticlesWithSummary(
{
publishingLevel: "PRODUCTION",
},
{
bodyContains: searchParams.q,
},
searchParams.q
? {
bodyContains: searchParams.q,
}
: undefined,
true,
);

Expand All @@ -23,7 +29,7 @@ export default async function SearchPage({ searchParams }) {
);
}

export function generateMetadata({ searchParams }) {
export function generateMetadata({ searchParams }: Props) {
return {
title: `Search results for "${searchParams.q}"`,
description: `Search results for "${searchParams.q}"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export default function SearchResults({
<div className="w-full whitespace-pre-wrap break-words py-4">
{isLoading ? (
<Skeleton count={5} />
) : (
) : summary ? (
<Markdown>{summary}</Markdown>
)}
) : null}
</div>
</section>
) : null}

<div className="my-16 max-w-[707px]">
{isLoading || searchResults?.length > 0 ? (
{isLoading || (searchResults && searchResults.length > 0) ? (
(searchResults ?? Array.from({ length: 5 })).map((result, index) => (
<Fragment key={result?.id || index}>
<div>
Expand All @@ -59,11 +59,11 @@ export default function SearchResults({
<p className="my-2 line-clamp-4 whitespace-pre-wrap">
{isLoading ? (
<Skeleton count={4} />
) : (
) : result.snippet ? (
markdownToTxt(
result.snippet.replaceAll(/{#h\..*}\n/g, "\n"),
)
)}
) : null}
</p>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {
articles: PaginatedArticle[] | ArticleWithoutContent[];
totalCount: number;
cursor: string;
fetcher: (cursor: string) => Promise<{
fetcher: (cursor?: string | null | undefined) => Promise<{
data: PaginatedArticle[] | ArticleWithoutContent[];
newCursor: string;
}>;
Expand Down
16 changes: 9 additions & 7 deletions starters/nextjs-starter-approuter-ts/components/article-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,32 @@ const ArticleHeader = ({
articleTitle: string;
seoMetadata: Metadata;
}) => {
const author = Array.isArray(seoMetadata.authors)
? seoMetadata.authors[0]
: seoMetadata.authors;

return (
<div>
<div className="text-5xl font-bold">{articleTitle}</div>
<div className="border-y-base-300 text-neutral-content mb-14 mt-6 flex w-full flex-row gap-x-4 border-y-[1px] py-4">
{seoMetadata.authors?.[0]?.name ? (
{author?.name ? (
<>
<div>
<Link
data-testid="author"
className="flex flex-row items-center gap-x-2 font-thin uppercase text-black no-underline"
href={`/authors/${seoMetadata.authors?.[0]?.name}`}
href={`/authors/${author?.name}`}
>
<div>
<Image
className="m-0 rounded-full"
src="/images/no-avatar.png"
width={24}
height={24}
alt={`Avatar of ${seoMetadata.authors?.[0]?.name}`}
alt={`Avatar of ${author?.name}`}
/>
</div>
<div className="underline">
{seoMetadata.authors?.[0]?.name}
</div>
<div className="underline">{author?.name}</div>
</Link>
</div>
<div className="h-full w-[1px] bg-[#e5e7eb]">&nbsp;</div>
Expand Down Expand Up @@ -118,7 +120,7 @@ export function StaticArticleView({ article, onlyContent }: ArticleViewProps) {
<>
<ArticleHeader
article={article}
articleTitle={articleTitle}
articleTitle={articleTitle || ""}
seoMetadata={seoMetadata}
/>
<ArticleRenderer
Expand Down
Loading

0 comments on commit dff8ed9

Please sign in to comment.