refactor: add next-seo (#531)
* refactor: add next-seo * refactor: change naming of seo component
This commit is contained in:
1 parent
fc50821282
commit
a37411b8af
33 files changed
+290
-298
No files matched your search
+12
-1
@@ -3,7 +3,7 @@ import React, { Fragment, useEffect, useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { signOut, useSession } from "next-auth/client";
|
||||
import { Menu, Transition } from "@headlessui/react";
|
||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../lib/telemetry";
|
||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
|
||||
import { SelectorIcon } from "@heroicons/react/outline";
|
||||
import {
|
||||
CalendarIcon,
|
||||
@@ -20,6 +20,7 @@ import classNames from "@lib/classNames";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
import Avatar from "@components/Avatar";
|
||||
import { User } from "@prisma/client";
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
|
||||
export default function Shell(props) {
|
||||
const router = useRouter();
|
||||
@@ -70,8 +71,18 @@ export default function Shell(props) {
|
||||
router.replace("/auth/login");
|
||||
}
|
||||
|
||||
const pageTitle = typeof props.heading === "string" ? props.heading : props.title;
|
||||
|
||||
return session ? (
|
||||
<>
|
||||
<HeadSeo
|
||||
title={pageTitle}
|
||||
description={props.subtitle}
|
||||
nextSeoProps={{
|
||||
nofollow: true,
|
||||
noindex: true,
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<Toaster position="bottom-right" />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import { NextSeo, NextSeoProps } from "next-seo";
|
||||
import React from "react";
|
||||
import { getBrowserInfo } from "@lib/core/browser/browser.utils";
|
||||
import { getSeoImage, seoConfig } from "@lib/config/next-seo.config";
|
||||
import merge from "lodash.merge";
|
||||
|
||||
export type HeadSeoProps = {
|
||||
title: string;
|
||||
description: string;
|
||||
siteName?: string;
|
||||
name?: string;
|
||||
avatar?: string;
|
||||
url?: string;
|
||||
canonical?: string;
|
||||
nextSeoProps?: NextSeoProps;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build full seo tags from title, desc, canonical and url
|
||||
*/
|
||||
const buildSeoMeta = (pageProps: {
|
||||
title: string;
|
||||
description: string;
|
||||
image: string;
|
||||
siteName?: string;
|
||||
url?: string;
|
||||
canonical?: string;
|
||||
}): NextSeoProps => {
|
||||
const { title, description, image, canonical, siteName = seoConfig.headSeo.siteName } = pageProps;
|
||||
return {
|
||||
title: title,
|
||||
canonical: canonical,
|
||||
openGraph: {
|
||||
site_name: siteName,
|
||||
type: "website",
|
||||
title: title,
|
||||
description: description,
|
||||
images: [
|
||||
{
|
||||
url: image,
|
||||
//width: 1077,
|
||||
//height: 565,
|
||||
//alt: "Alt image"
|
||||
},
|
||||
],
|
||||
},
|
||||
additionalMetaTags: [
|
||||
{
|
||||
property: "name",
|
||||
content: title,
|
||||
},
|
||||
{
|
||||
property: "description",
|
||||
content: description,
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
content: description,
|
||||
},
|
||||
{
|
||||
property: "image",
|
||||
content: image,
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
const constructImage = (name: string, avatar: string, description: string): string => {
|
||||
return (
|
||||
encodeURIComponent("Meet **" + name + "** <br>" + description).replace(/'/g, "%27") +
|
||||
".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" +
|
||||
encodeURIComponent(avatar)
|
||||
);
|
||||
};
|
||||
|
||||
export const HeadSeo: React.FC<HeadSeoProps & { children?: never }> = (props) => {
|
||||
const defaultUrl = getBrowserInfo()?.url;
|
||||
const image = getSeoImage("default");
|
||||
|
||||
const {
|
||||
title,
|
||||
description,
|
||||
name = null,
|
||||
avatar = null,
|
||||
siteName,
|
||||
canonical = defaultUrl,
|
||||
nextSeoProps = {},
|
||||
} = props;
|
||||
|
||||
const pageTitle = title + " | Calendso";
|
||||
let seoObject = buildSeoMeta({ title: pageTitle, image, description, canonical, siteName });
|
||||
|
||||
if (name && avatar) {
|
||||
const pageImage = getSeoImage("ogImage") + constructImage(name, avatar, description);
|
||||
seoObject = buildSeoMeta({ title: pageTitle, description, image: pageImage, canonical, siteName });
|
||||
}
|
||||
|
||||
const seoProps: NextSeoProps = merge(nextSeoProps, seoObject);
|
||||
|
||||
return <NextSeo {...seoProps} />;
|
||||
};
|
||||
Reference in new issue
Block a user