diff --git a/.changeset/good-weeks-agree.md b/.changeset/good-weeks-agree.md new file mode 100644 index 00000000..c71306bc --- /dev/null +++ b/.changeset/good-weeks-agree.md @@ -0,0 +1,10 @@ +--- +"@pantheon-systems/next-approuter-pcc-starter-ts": patch +"@pantheon-systems/pcc-react-sample-library": patch +"@pantheon-systems/pcc-react-sdk": patch +"@pantheon-systems/pcc-browser-sdk": patch +"@pantheon-systems/pcc-sdk-core": patch +"@pantheon-systems/pcc-cli": patch +--- + +Use 'label' for metadata group record identifiers instead of 'name' diff --git a/.changeset/pre.json b/.changeset/pre.json new file mode 100644 index 00000000..05b4eb7b --- /dev/null +++ b/.changeset/pre.json @@ -0,0 +1,29 @@ +{ + "mode": "pre", + "tag": "beta", + "initialVersions": { + "eslint-config-pcc-custom": "1.0.0", + "testpages": "0.1.0", + "@pantheon-systems/pcc-browser-sdk": "3.9.0", + "@pantheon-systems/pcc-cli": "3.9.0", + "@pantheon-systems/pcc-sdk-core": "3.9.0", + "@pantheon-systems/pcc-react-sample-library": "3.9.0", + "@pantheon-systems/pcc-react-sdk": "3.9.0", + "@pantheon-systems/pcc-vue-sdk": "3.9.0", + "gatsby-pcc-starter": "1.0.0", + "gatsby-pcc-starter-ts": "1.0.0", + "@pantheon-systems/next-pcc-starter": "1.0.0", + "@pantheon-systems/next-approuter-pcc-starter-ts": "1.1.8", + "@pantheon-systems/next-pcc-starter-ts": "1.0.0", + "@pantheon-systems/vue-pcc-starter": "1.1.3", + "@pantheon-systems/vue-pcc-starter-ts": "1.1.3" + }, + "changesets": [ + "good-weeks-agree", + "plenty-rice-cheer", + "proud-socks-cry", + "seven-owls-poke", + "sixty-moose-act", + "ten-cats-swim" + ] +} diff --git a/.changeset/seven-owls-poke.md b/.changeset/seven-owls-poke.md new file mode 100644 index 00000000..5dc1891a --- /dev/null +++ b/.changeset/seven-owls-poke.md @@ -0,0 +1,5 @@ +--- +"@pantheon-systems/pcc-sdk-core": patch +--- + +Allow caller to retrieve all metadata groups, optionally hydrated. diff --git a/.changeset/sixty-moose-act.md b/.changeset/sixty-moose-act.md new file mode 100644 index 00000000..7008d743 --- /dev/null +++ b/.changeset/sixty-moose-act.md @@ -0,0 +1,5 @@ +--- +"@pantheon-systems/pcc-sdk-core": minor +--- + +Add support for metadata groups (like authors). diff --git a/packages/browser/CHANGELOG.md b/packages/browser/CHANGELOG.md index 8e9ece3f..915e6e77 100644 --- a/packages/browser/CHANGELOG.md +++ b/packages/browser/CHANGELOG.md @@ -1,5 +1,27 @@ # @pantheon-systems/pcc-browser-sdk +## 3.10.0-beta.2 + +### Patch Changes + +- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name' +- Updated dependencies [67bc79b] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.2 + +## 3.10.0-beta.1 + +### Patch Changes + +- Updated dependencies [400fc48] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.1 + +## 3.10.0-beta.0 + +### Patch Changes + +- Updated dependencies [572fb97] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.0 + ## 3.9.0 ### Patch Changes diff --git a/packages/browser/package.json b/packages/browser/package.json index 09dfa1f2..ab5f73ff 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -2,7 +2,7 @@ "name": "@pantheon-systems/pcc-browser-sdk", "author": "@pantheon-systems", "description": "Pantheon Content Cloud Browser SDK", - "version": "3.9.0", + "version": "3.10.0-beta.2", "main": "dist/index.js", "files": [ "dist", diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 589afdb8..8ef84384 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,34 @@ # @pantheon-systems/pcc-cli +## 3.10.0-beta.2 + +### Minor Changes + +- 0b3ee7b: No longer download turbo.json when initializing a new project from + the starter kit. + +### Patch Changes + +- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name' +- 39b7604: Added a warning message when CLI build is pointing to non-production + environment. +- Updated dependencies [67bc79b] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.2 + +## 3.10.0-beta.1 + +### Patch Changes + +- Updated dependencies [400fc48] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.1 + +## 3.10.0-beta.0 + +### Patch Changes + +- Updated dependencies [572fb97] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.0 + ## 3.9.0 ### Patch Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 53f1d95e..216ff1fd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -2,7 +2,7 @@ "name": "@pantheon-systems/pcc-cli", "author": "@pantheon-systems", "description": "Pantheon Content Cloud CLI", - "version": "3.9.0", + "version": "3.10.0-beta.2", "type": "module", "license": "MIT", "keywords": [ diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 2ade679d..b7446bf3 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,23 @@ # @pantheon-systems/pcc-sdk-core +## 3.10.0-beta.2 + +### Patch Changes + +- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name' + +## 3.10.0-beta.1 + +### Patch Changes + +- 400fc48: Allow caller to retrieve all metadata groups, optionally hydrated. + +## 3.10.0-beta.0 + +### Minor Changes + +- 572fb97: Add support for metadata groups (like authors). + ## 3.9.0 ### Minor Changes diff --git a/packages/core/package.json b/packages/core/package.json index 055a1a51..acceb14e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -2,7 +2,7 @@ "name": "@pantheon-systems/pcc-sdk-core", "author": "@pantheon-systems", "description": "Pantheon Content Cloud SDK Core", - "version": "3.9.0", + "version": "3.10.0-beta.2", "license": "MIT", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/packages/core/src/core/pantheon-api.ts b/packages/core/src/core/pantheon-api.ts index 6cb64cd5..ac991990 100644 --- a/packages/core/src/core/pantheon-api.ts +++ b/packages/core/src/core/pantheon-api.ts @@ -1,7 +1,7 @@ import queryString from "query-string"; import { getArticleBySlugOrId, PCCConvenienceFunctions } from "../helpers"; import { parseJwt } from "../lib/jwt"; -import { Article, SmartComponentMap } from "../types"; +import { Article, MetadataGroup, SmartComponentMap } from "../types"; import { PantheonClient, PantheonClientConfig } from "./pantheon-client"; export interface ApiRequest { @@ -85,6 +85,11 @@ export interface PantheonAPIOptions { * Map of smart component names to their schemas. */ smartComponentMap?: SmartComponentMap; + + /** + * Metadata groups, schemas, and how to retrieve their data. + */ + metadataGroups?: MetadataGroup[]; } const defaultOptions = { @@ -238,6 +243,53 @@ export const PantheonAPI = (givenOptions?: PantheonAPIOptions) => { return await res.redirect(302, options.notFoundPath); } + case "metadata_group": { + const groupIdentifier = command[1]; + const objectId = command[2]; + + if (options.metadataGroups == null) { + return res.json({ + error: "This collection has no metadata groups defined.", + }); + } + + if (groupIdentifier == null) { + return res.json({ + rows: await Promise.all( + options.metadataGroups.map( + async ({ label, groupIdentifier, schema, list }) => ({ + label, + groupIdentifier, + schema, + values: + restOfQuery.hydrate === "true" ? await list() : undefined, + }), + ), + ), + }); + } + + const group = await options.metadataGroups.find( + (x) => x.groupIdentifier === groupIdentifier, + ); + + if (!group) { + return res.json({ + error: "Could not find matching group by given identifier.", + }); + } + + if (!objectId) { + return res.json({ + rows: await group.list(), + }); + } + + return res.json({ + row: await group.get(objectId), + }); + } + default: { return await res.redirect(302, options.notFoundPath); } diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index e835133f..faa74766 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -108,11 +108,37 @@ export interface PantheonTreeNode { id?: string; type?: string; } + export interface PantheonTree { version: string; children: PantheonTreeNode[]; } +interface MetadataGroupRowEssentials { + label: string; +} + +export interface MetadataGroup { + label: string; + groupIdentifier: string; + schema?: Record< + string, + "string" | "textarea" | "number" | "boolean" | "date" | "file" + >; + get: ( + id: string, + ) => + | Promise<(unknown & MetadataGroupRowEssentials) | null | undefined> + | (unknown & MetadataGroupRowEssentials) + | null + | undefined; + list: () => + | Promise<(unknown & MetadataGroupRowEssentials)[] | null | undefined> + | (unknown & MetadataGroupRowEssentials)[] + | null + | undefined; +} + const fieldTypes = z.enum([ "string", "textarea", diff --git a/packages/react-sample-library/CHANGELOG.md b/packages/react-sample-library/CHANGELOG.md index 69895f72..2e7f7b03 100644 --- a/packages/react-sample-library/CHANGELOG.md +++ b/packages/react-sample-library/CHANGELOG.md @@ -1,5 +1,31 @@ # @pantheon-systems/pcc-vue-sdk +## 3.10.0-beta.2 + +### Patch Changes + +- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name' +- Updated dependencies [67bc79b] +- Updated dependencies [b89c5ee] + - @pantheon-systems/pcc-react-sdk@3.10.0-beta.2 + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.2 + +## 3.10.0-beta.1 + +### Patch Changes + +- Updated dependencies [400fc48] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.1 + - @pantheon-systems/pcc-react-sdk@3.10.0-beta.1 + +## 3.10.0-beta.0 + +### Patch Changes + +- Updated dependencies [572fb97] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.0 + - @pantheon-systems/pcc-react-sdk@3.10.0-beta.0 + ## 3.9.0 ### Patch Changes diff --git a/packages/react-sample-library/package.json b/packages/react-sample-library/package.json index fa4c6da1..0a8e430c 100644 --- a/packages/react-sample-library/package.json +++ b/packages/react-sample-library/package.json @@ -2,7 +2,7 @@ "name": "@pantheon-systems/pcc-react-sample-library", "author": "@pantheon-systems", "description": "Pantheon Content Cloud Sample Component Library for React", - "version": "3.9.0", + "version": "3.10.0-beta.2", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", diff --git a/packages/react-sdk/CHANGELOG.md b/packages/react-sdk/CHANGELOG.md index 3e94fcc3..bbabf955 100644 --- a/packages/react-sdk/CHANGELOG.md +++ b/packages/react-sdk/CHANGELOG.md @@ -1,5 +1,32 @@ # @pantheon-systems/pcc-react-sdk +## 3.10.0-beta.2 + +### Minor Changes + +- b89c5ee: The injected preview bar is deprecated in favor of the integrated + preview bar in the dashboard preview interface + +### Patch Changes + +- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name' +- Updated dependencies [67bc79b] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.2 + +## 3.10.0-beta.1 + +### Patch Changes + +- Updated dependencies [400fc48] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.1 + +## 3.10.0-beta.0 + +### Patch Changes + +- Updated dependencies [572fb97] + - @pantheon-systems/pcc-sdk-core@3.10.0-beta.0 + ## 3.9.0 ### Minor Changes diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json index 31d435da..c9bd970b 100644 --- a/packages/react-sdk/package.json +++ b/packages/react-sdk/package.json @@ -2,7 +2,7 @@ "name": "@pantheon-systems/pcc-react-sdk", "author": "@pantheon-systems", "description": "Pantheon Content Cloud React SDK", - "version": "3.9.0", + "version": "3.10.0-beta.2", "license": "MIT", "keywords": [ "pcc", diff --git a/starters/gatsby-starter-ts/package.json b/starters/gatsby-starter-ts/package.json index 11fe6def..5f91d7da 100644 --- a/starters/gatsby-starter-ts/package.json +++ b/starters/gatsby-starter-ts/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@mdx-js/react": "2.3.0", - "@pantheon-systems/pcc-react-sdk": "~3.9.0", + "@pantheon-systems/pcc-react-sdk": "~3.10.0-beta.2", "@pantheon-systems/pds-toolkit-react": "1.0.0-dev.55", "autoprefixer": "^10.4.17", "gatsby": "5.13.5", diff --git a/starters/gatsby-starter/package.json b/starters/gatsby-starter/package.json index 3d198cca..590cbba0 100644 --- a/starters/gatsby-starter/package.json +++ b/starters/gatsby-starter/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@mdx-js/react": "2.3.0", - "@pantheon-systems/pcc-react-sdk": "3.9.0", + "@pantheon-systems/pcc-react-sdk": "3.10.0-beta.2", "@pantheon-systems/pds-toolkit-react": "1.0.0-dev.55", "autoprefixer": "^10.4.17", "gatsby": "5.13.5", diff --git a/starters/nextjs-starter-approuter-ts/CHANGELOG.md b/starters/nextjs-starter-approuter-ts/CHANGELOG.md index 0839f857..8d91bdfc 100644 --- a/starters/nextjs-starter-approuter-ts/CHANGELOG.md +++ b/starters/nextjs-starter-approuter-ts/CHANGELOG.md @@ -1,5 +1,20 @@ # @pantheon-systems/next-pcc-starter +## 1.1.9-beta.1 + +### Patch Changes + +- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name' +- Updated dependencies [67bc79b] +- Updated dependencies [b89c5ee] + - @pantheon-systems/pcc-react-sdk@3.10.0-beta.2 + +## 1.1.9-beta.0 + +### Patch Changes + +- @pantheon-systems/pcc-react-sdk@3.10.0-beta.0 + ## 1.1.8 ### Patch Changes diff --git a/starters/nextjs-starter-approuter-ts/app/api/pantheoncloud/[...command]/api-options.ts b/starters/nextjs-starter-approuter-ts/app/api/pantheoncloud/[...command]/api-options.ts index 922ceb1f..6dfb222c 100644 --- a/starters/nextjs-starter-approuter-ts/app/api/pantheoncloud/[...command]/api-options.ts +++ b/starters/nextjs-starter-approuter-ts/app/api/pantheoncloud/[...command]/api-options.ts @@ -1,5 +1,9 @@ import { PantheonAPIOptions } from "@pantheon-systems/pcc-react-sdk/server"; import { serverSmartComponentMap } from "../../../../components/smart-components/server-components"; +import { + getAuthorById, + listAuthors, +} from "../../../../lib/pcc-metadata-groups"; export const pantheonAPIOptions: PantheonAPIOptions = { resolvePath: (article) => `/articles/${article.slug || article.id}`, @@ -7,4 +11,16 @@ export const pantheonAPIOptions: PantheonAPIOptions = { smartComponentMap: serverSmartComponentMap, componentPreviewPath: (componentName) => `/component-preview/${componentName}`, + metadataGroups: [ + { + label: "Author", + groupIdentifier: "AUTHOR", + schema: { + name: "string", + image: "file", + }, + get: getAuthorById, + list: listAuthors, + }, + ], }; diff --git a/starters/nextjs-starter-approuter-ts/lib/pcc-metadata-groups.ts b/starters/nextjs-starter-approuter-ts/lib/pcc-metadata-groups.ts new file mode 100644 index 00000000..764b6ed8 --- /dev/null +++ b/starters/nextjs-starter-approuter-ts/lib/pcc-metadata-groups.ts @@ -0,0 +1,27 @@ +export interface Author { + id: string | number; + label: string; + image: string; +} + +const authors = [ + { + id: 1, + label: "James T. Kirk", + image: "https://en.wikipedia.org/wiki/File:William_Shatner_Star_Trek.JPG", + }, + { + id: 2, + label: "Spock", + image: + "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Leonard_Nimoy_as_Spock_1967.jpg/440px-Leonard_Nimoy_as_Spock_1967.jpg", + }, +]; + +export function getAuthorById(id: string) { + return authors.find((x) => x.id?.toString() === id); +} + +export function listAuthors() { + return authors; +} diff --git a/starters/nextjs-starter-approuter-ts/lib/utils.ts b/starters/nextjs-starter-approuter-ts/lib/utils.ts index d3b3a6ca..1f20eafd 100644 --- a/starters/nextjs-starter-approuter-ts/lib/utils.ts +++ b/starters/nextjs-starter-approuter-ts/lib/utils.ts @@ -2,6 +2,7 @@ import { ArticleWithoutContent } from "@pantheon-systems/pcc-react-sdk"; import { clsx, type ClassValue } from "clsx"; import { Metadata } from "next"; import { twMerge } from "tailwind-merge"; +import { getAuthorById } from "./pcc-metadata-groups"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); @@ -40,7 +41,7 @@ export function getSeoMetadata( ? String(article.metadata?.description) : "Article hosted using Pantheon Content Cloud"; - let authors: Metadata["authors"] = []; + const authors: Metadata["authors"] = []; // Collecting data from metadata fields Object.entries(article.metadata || {}).forEach(([k, v]) => { @@ -49,7 +50,17 @@ export function getSeoMetadata( switch (key) { case "author": { if (typeof v === "string") { - authors = [{ name: v }]; + authors.push({ name: v }); + } + break; + } + case "complex-author": { + if (typeof v === "string") { + const authorName = getAuthorById(v)?.label; + + if (authorName) { + authors.push({ name: v }); + } } break; } diff --git a/starters/nextjs-starter-approuter-ts/package.json b/starters/nextjs-starter-approuter-ts/package.json index 8dad24fb..3ca01208 100644 --- a/starters/nextjs-starter-approuter-ts/package.json +++ b/starters/nextjs-starter-approuter-ts/package.json @@ -1,6 +1,6 @@ { "name": "@pantheon-systems/next-approuter-pcc-starter-ts", - "version": "1.1.8", + "version": "1.1.9-beta.1", "private": true, "license": "GPL-3.0-or-later", "description": "A starter for building a Pantheon Content Cloud (PCC) powered site with Next.js App Router and TypeScript", @@ -26,7 +26,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@pantheon-systems/pcc-react-sdk": "~3.9.0", + "@pantheon-systems/pcc-react-sdk": "~3.10.0-beta.2", "@radix-ui/react-popover": "^1.1.1", "@radix-ui/react-slot": "^1.1.0", "@tailwindcss/typography": "0.5.10", diff --git a/starters/nextjs-starter-ts/lib/pcc-metadata-groups.ts b/starters/nextjs-starter-ts/lib/pcc-metadata-groups.ts new file mode 100644 index 00000000..764b6ed8 --- /dev/null +++ b/starters/nextjs-starter-ts/lib/pcc-metadata-groups.ts @@ -0,0 +1,27 @@ +export interface Author { + id: string | number; + label: string; + image: string; +} + +const authors = [ + { + id: 1, + label: "James T. Kirk", + image: "https://en.wikipedia.org/wiki/File:William_Shatner_Star_Trek.JPG", + }, + { + id: 2, + label: "Spock", + image: + "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Leonard_Nimoy_as_Spock_1967.jpg/440px-Leonard_Nimoy_as_Spock_1967.jpg", + }, +]; + +export function getAuthorById(id: string) { + return authors.find((x) => x.id?.toString() === id); +} + +export function listAuthors() { + return authors; +} diff --git a/starters/nextjs-starter-ts/lib/utils.ts b/starters/nextjs-starter-ts/lib/utils.ts index 47404737..f6ea108b 100644 --- a/starters/nextjs-starter-ts/lib/utils.ts +++ b/starters/nextjs-starter-ts/lib/utils.ts @@ -2,6 +2,7 @@ import { ArticleWithoutContent } from "@pantheon-systems/pcc-react-sdk"; import { clsx, type ClassValue } from "clsx"; import { OpenGraph } from "next-seo/lib/types"; import { twMerge } from "tailwind-merge"; +import { getAuthorById } from "./pcc-metadata-groups"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); @@ -38,7 +39,7 @@ export function getSeoMetadata(article: ArticleWithoutContent) { ? String(article.metadata?.description) : "Article hosted using Pantheon Content Cloud"; - let authors: string[] = []; + const authors: string[] = []; let publishedTime: number | null = article.publishedDate; // Collecting data from metadata fields @@ -48,7 +49,17 @@ export function getSeoMetadata(article: ArticleWithoutContent) { switch (key) { case "author": { if (typeof v === "string") { - authors = [v]; + authors.push(v); + } + break; + } + case "complex-author": { + if (typeof v === "string") { + const authorName = getAuthorById(v)?.label; + + if (authorName) { + authors.push(v); + } } break; } diff --git a/starters/nextjs-starter-ts/package.json b/starters/nextjs-starter-ts/package.json index 4a024aa8..abd47c1f 100644 --- a/starters/nextjs-starter-ts/package.json +++ b/starters/nextjs-starter-ts/package.json @@ -26,7 +26,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@pantheon-systems/pcc-react-sdk": "~3.9.0", + "@pantheon-systems/pcc-react-sdk": "~3.10.0-beta.2", "@radix-ui/react-popover": "^1.1.1", "@radix-ui/react-slot": "^1.1.0", "@tailwindcss/typography": "0.5.10", diff --git a/starters/nextjs-starter-ts/pages/api/pantheoncloud/[...command].ts b/starters/nextjs-starter-ts/pages/api/pantheoncloud/[...command].ts index 328a185b..a2e22c56 100644 --- a/starters/nextjs-starter-ts/pages/api/pantheoncloud/[...command].ts +++ b/starters/nextjs-starter-ts/pages/api/pantheoncloud/[...command].ts @@ -3,12 +3,25 @@ import { PantheonAPIOptions, } from "@pantheon-systems/pcc-react-sdk"; import { serverSmartComponentMap } from "../../../components/smart-components"; +import { getAuthorById, listAuthors } from "../../../lib/pcc-metadata-groups"; export const pantheonAPIOptions: PantheonAPIOptions = { resolvePath: (article) => `/articles/${article.slug || article.id}`, smartComponentMap: serverSmartComponentMap, componentPreviewPath: (componentName) => `/component-preview/${componentName}`, + metadataGroups: [ + { + label: "Author", + groupIdentifier: "AUTHOR", + schema: { + name: "string", + image: "file", + }, + get: getAuthorById, + list: listAuthors, + }, + ], }; export default PantheonAPI(pantheonAPIOptions); diff --git a/starters/nextjs-starter/lib/pcc-metadata-groups.js b/starters/nextjs-starter/lib/pcc-metadata-groups.js new file mode 100644 index 00000000..cfd11f0d --- /dev/null +++ b/starters/nextjs-starter/lib/pcc-metadata-groups.js @@ -0,0 +1,21 @@ +const authors = [ + { + id: 1, + label: "James T. Kirk", + image: "https://en.wikipedia.org/wiki/File:William_Shatner_Star_Trek.JPG", + }, + { + id: 2, + label: "Spock", + image: + "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Leonard_Nimoy_as_Spock_1967.jpg/440px-Leonard_Nimoy_as_Spock_1967.jpg", + }, +]; + +export function getAuthorById(id) { + return authors.find((x) => x.id?.toString() === id); +} + +export function listAuthors() { + return authors; +} diff --git a/starters/nextjs-starter/lib/utils.js b/starters/nextjs-starter/lib/utils.js index 0d244d47..627bae9a 100644 --- a/starters/nextjs-starter/lib/utils.js +++ b/starters/nextjs-starter/lib/utils.js @@ -1,5 +1,6 @@ import { clsx } from "clsx"; import { twMerge } from "tailwind-merge"; +import { getAuthorById } from "./pcc-metadata-groups"; export function cn(...inputs) { return twMerge(clsx(inputs)); @@ -31,7 +32,7 @@ export function getSeoMetadata(article) { ? String(article.metadata?.description) : "Article hosted using Pantheon Content Cloud"; - let authors = []; + const authors = []; let publishedTime = article.publishedDate; // Collecting data from metadata fields @@ -41,7 +42,7 @@ export function getSeoMetadata(article) { switch (key) { case "author": { if (typeof v === "string") { - authors = [v]; + authors.push(v); } break; } @@ -52,6 +53,15 @@ export function getSeoMetadata(article) { } break; } + case "complex-author": + if (typeof v === "string") { + const authorName = getAuthorById(v)?.label; + + if (authorName) { + authors.push(v); + } + } + break; } }); diff --git a/starters/nextjs-starter/package.json b/starters/nextjs-starter/package.json index d57208e8..f3123963 100644 --- a/starters/nextjs-starter/package.json +++ b/starters/nextjs-starter/package.json @@ -26,7 +26,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@pantheon-systems/pcc-react-sdk": "~3.9.0", + "@pantheon-systems/pcc-react-sdk": "~3.10.0-beta.2", "@radix-ui/react-popover": "^1.1.1", "@radix-ui/react-slot": "^1.1.0", "@tailwindcss/typography": "0.5.10", diff --git a/starters/nextjs-starter/pages/api/pantheoncloud/[...command].js b/starters/nextjs-starter/pages/api/pantheoncloud/[...command].js index e8e90f73..d472a97d 100644 --- a/starters/nextjs-starter/pages/api/pantheoncloud/[...command].js +++ b/starters/nextjs-starter/pages/api/pantheoncloud/[...command].js @@ -1,11 +1,24 @@ import { PantheonAPI } from "@pantheon-systems/pcc-react-sdk"; import { serverSmartComponentMap } from "../../../components/smart-components"; +import { getAuthorById, listAuthors } from "../../../lib/pcc-metadata-groups"; export const pantheonAPIOptions = { resolvePath: (article) => `/articles/${article.slug || article.id}`, smartComponentMap: serverSmartComponentMap, componentPreviewPath: (componentName) => `/component-preview/${componentName}`, + metadataGroups: [ + { + label: "Author", + groupIdentifier: "AUTHOR", + schema: { + name: "string", + image: "file", + }, + get: getAuthorById, + list: listAuthors, + }, + ], }; export default PantheonAPI(pantheonAPIOptions);