Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add seo fields to pages #1454

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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