From 94354d75985c2df9de7d949ff881f7521136be84 Mon Sep 17 00:00:00 2001 From: nuno-aac Date: Tue, 26 Sep 2023 14:07:01 +0100 Subject: [PATCH] Add seo fields --- .../cms-config/src/collections/pages.ts | 23 +++++++++++++++++++ .../src/renderer/_default.page.server.tsx | 12 ++++++---- workspaces/website/src/renderer/types.ts | 6 +++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/workspaces/cms-config/src/collections/pages.ts b/workspaces/cms-config/src/collections/pages.ts index 266bace947..3e555db414 100644 --- a/workspaces/cms-config/src/collections/pages.ts +++ b/workspaces/cms-config/src/collections/pages.ts @@ -30,6 +30,29 @@ export const pagesCollectionConfig = { label: "Show title", widget: "boolean" }, + { + required: false, + name: "seoTitle", + label: "Seo title", + hint: "If empty the title field will be used", + widget: "string", + crowdin: true, + }, + { + required: false, + name: "seoDescription", + label: "Seo description", + widget: "string", + crowdin: true, + }, + { + required: false, + name: "seoFocusKeywords", + label: "Seo focus keywords", + hint: "Enter the focus keywords separated by commas", + widget: 'list', + crowdin: true, + }, { name: "template", widget: "select", diff --git a/workspaces/website/src/renderer/_default.page.server.tsx b/workspaces/website/src/renderer/_default.page.server.tsx index 414055c207..fb67c75e71 100644 --- a/workspaces/website/src/renderer/_default.page.server.tsx +++ b/workspaces/website/src/renderer/_default.page.server.tsx @@ -1,6 +1,6 @@ import { renderToStream } from "react-streaming/server"; import { escapeInject } from "vite-plugin-ssr/server"; -import { PageContextServer } from "./types"; +import { PageContextServer, SeoType } from "./types"; import { PageShell } from "./PageShell"; import { getDefaultPageContext } from "./helpers"; import type { InjectFilterEntry } from "vite-plugin-ssr/types"; @@ -41,20 +41,23 @@ export async function render(pageContext: PageContextServer) { }); const GOOGLE_TAG_ID = "G-WY42TERK5P"; + const pageSeo = pageProps?.data as SeoType const documentProps = pageContext.documentProps ?? pageContext.exports.documentProps; - const title = documentProps?.title - ? `${documentProps?.title} - Starknet` + const title = documentProps?.title ?? pageSeo?.seoTitle + ? `${documentProps?.title ?? pageSeo?.seoTitle} - Starknet` : "Starknet"; const description = - documentProps?.description ?? + documentProps?.description ?? pageSeo?.seoDescription as string ?? "Starknet is the secure scaling technology bringing Ethereum’s benefits to the world."; const image = documentProps?.image ?? `${import.meta.env.VITE_SITE_URL}/assets/share/generic_landing.png`; + + const focusKeywords = pageSeo?.seoFocusKeywords as string[] const documentHtml = escapeInject` @@ -66,6 +69,7 @@ export async function render(pageContext: PageContextServer) { ${title} + diff --git a/workspaces/website/src/renderer/types.ts b/workspaces/website/src/renderer/types.ts index 0c64a6e0ee..c92ec4d1cf 100644 --- a/workspaces/website/src/renderer/types.ts +++ b/workspaces/website/src/renderer/types.ts @@ -23,6 +23,12 @@ export interface DocumentProps { video?: string; } +export type SeoType = { + seoTitle?: string; + seoDescription?: string; + seoFocusKeywords?: string[]; +} + export type PageContextCustom = { Page: Page; pageProps?: PageProps;