Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

[SEO] Add meta tags #17

Merged
merged 5 commits into from
Dec 5, 2024
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
141 changes: 102 additions & 39 deletions components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,107 @@ import FooterSlackCTA from './FooterSlackCTA';
import SubFooter from './SubFooter';
import ThemeChanger from './ThemeChanger';

const Layout = ({ title, children, lastPublishedAt }: LayoutProps) => (
<>
<Head>
<title>{title}</title>
<link rel="icon" href="/favicon.ico" />
<link
rel="preload"
href="/fonts/inter/inter-regular.woff2"
as="font"
crossOrigin=""
/>
<link
rel="preload"
href="/fonts/inter/inter-bold.woff2"
as="font"
crossOrigin=""
/>
<link
rel="preload"
href="/fonts/inter/inter-black.woff2"
as="font"
crossOrigin=""
/>
</Head>
<div className={styles.container}>
<header className={styles.header}>
<HeadingSlackCTA />
<ThemeChanger />
</header>
<main className={styles.main}>
<div className={styles.content}>{children}</div>
</main>
<footer className={styles.footer}>
<FooterSlackCTA />
<SubFooter lastPublishedAt={lastPublishedAt} />
</footer>
</div>
</>
);
const Layout = ({ title, meta, lastPublishedAt, children }: LayoutProps) => {
const metaTitle = meta.seoTitle ? meta.seoTitle : title;
const metaDescription = meta.socialText
? meta.socialText
: meta.searchDescription;
const metaURL = `https://areweheadlessyet.wagtail.org/${
meta.slug !== 'are-we-headless-yet' ? meta.slug : ''
}`;

return (
<>
<Head>
<title>{title}</title>
<meta name="description" content={meta.searchDescription} />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>

<meta property="og:type" content="website" />
<meta property="og:url" content={metaURL} />
<meta property="og:title" content={metaTitle} />
<meta property="og:description" content={metaDescription} />
<meta property="og:image" content={meta.socialImageUrl} />
<meta
property="og:site_name"
content="Are We Headless Yet - Wagtail CMS"
/>
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={metaURL} />
<meta property="twitter:title" content={metaTitle} />
<meta
property="twitter:description"
content={metaDescription}
/>
<meta property="twitter:image" content={meta.socialImageUrl} />

<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicons/favicon-16x16.png"
/>
<link rel="manifest" href="/favicons/site.webmanifest" />
<link
rel="mask-icon"
href="/favicons/safari-pinned-tab.svg"
color="#5bbad5"
/>
<link rel="shortcut icon" href="/favicons/favicon.ico" />
<meta name="msapplication-TileColor" content="#2b5797" />
<meta
name="msapplication-config"
content="/favicons/browserconfig.xml"
/>
<meta name="theme-color" content="#ffffff" />
<link
rel="preload"
href="/fonts/inter/inter-regular.woff2"
as="font"
crossOrigin=""
/>
<link
rel="preload"
href="/fonts/inter/inter-bold.woff2"
as="font"
crossOrigin=""
/>
<link
rel="preload"
href="/fonts/inter/inter-black.woff2"
as="font"
crossOrigin=""
/>
</Head>
<div className={styles.container}>
<header className={styles.header}>
<HeadingSlackCTA />
<ThemeChanger />
</header>
<main className={styles.main}>
<div className={styles.content}>{children}</div>
</main>
<footer className={styles.footer}>
<FooterSlackCTA />
<SubFooter lastPublishedAt={lastPublishedAt} />
</footer>
</div>
</>
);
};

export default Layout;
3 changes: 3 additions & 0 deletions components/Layout/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AreWeHeadlessYetPageMeta } from '../types';

type LayoutProps = {
title: string;
lastPublishedAt: string;
meta: AreWeHeadlessYetPageMeta;
children?: React.ReactNode;
};

Expand Down
12 changes: 10 additions & 2 deletions components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ export default interface StreamFieldBlock {
id: string;
}

export interface AreWeHeadlessYetPageMeta {
slug: string;
searchDescription: string;
seoTitle?: string;
socialImageUrl?: string;
socialText?: string;
}

export interface AreWeHeadlessYetHomePage {
id: number;
meta: { [key: string]: string | boolean | null };
meta: AreWeHeadlessYetPageMeta;
title: string;
lastPublishedAt: string;
straplineIcon: IconChoice;
Expand All @@ -19,7 +27,7 @@ export interface AreWeHeadlessYetHomePage {

export interface AreWeHeadlessYetTopicPage {
id: number;
meta: { [key: string]: string | boolean | null };
meta: AreWeHeadlessYetPageMeta;
title: string;
lastPublishedAt: string;
statusColor: StatusColorChoice;
Expand Down
6 changes: 5 additions & 1 deletion pages/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import TopicPageHero from '../components/TopicPageHero/TopicPageHero';
import StreamField from '../components/StreamField';

const TopicPage: NextPage<{ page: AreWeHeadlessYetTopicPage }> = ({ page }) => (
<Layout title={page.title} lastPublishedAt={page.lastPublishedAt}>
<Layout
title={page.title}
meta={page.meta}
lastPublishedAt={page.lastPublishedAt}
>
<TopicPageHero {...page} />
<StreamField body={page.body} className="container--topic-page" />
</Layout>
Expand Down
1 change: 1 addition & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Home: NextPage<{ page: AreWeHeadlessYetHomePage; topics: Topics }> = ({
}) => (
<Layout
title="Are we headless yet? Yes! | Wagtail"
meta={page.meta}
lastPublishedAt={page.lastPublishedAt}
>
<HomeHero icon={page.straplineIcon} text={page.straplineText} />
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
Binary file added public/favicons/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions public/favicons/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/icons/mstile-150x150.png"/>
<TileColor>#2b5797</TileColor>
</tile>
</msapplication>
</browserconfig>
Binary file added public/favicons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicons/favicon.ico
Binary file not shown.
Binary file added public/favicons/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions public/favicons/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions public/favicons/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "AreWeHeadlessYet",
"short_name": "AreWeHeadlessYet",
"icons": [
{
"src": "/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
Loading