Skip to content

Commit

Permalink
Add seo fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nuno-aac committed Sep 27, 2023
1 parent 21720eb commit 94354d7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
23 changes: 23 additions & 0 deletions workspaces/cms-config/src/collections/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions workspaces/website/src/renderer/_default.page.server.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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`<!DOCTYPE html>
<html>
Expand All @@ -66,6 +69,7 @@ export async function render(pageContext: PageContextServer) {
<title>${title}</title>
<meta name="title" content="${title}">
<meta name="description" content="${description}">
<meta name="keywords" content="${focusKeywords?.join(',') ?? "starknet"}">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="article">
Expand Down
6 changes: 6 additions & 0 deletions workspaces/website/src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 94354d7

Please sign in to comment.