Skip to content
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
44 changes: 44 additions & 0 deletions src/components/Meta/Meta.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const locales = {
en: 'en_US',
ko: 'ko_KR',
};

export const Meta = ({ data }): JSX.Element => {
const lang = locales[data.locale] || locales.en;
const { title } = data;
const { description } = data;
const image = data.image !== undefined && `${data.image}`;
const canonical = 'https://hanspoon-31cd9.web.app/';
const type = data.type === undefined ? 'website' : data.type;
const width = data.image && (data.width || 1200);
const height = data.image && (data.height || 630);

return (
<>
<title>{`${title} - HanSpoon`}</title>
<meta name="description" content={description} />
{canonical ? <link rel="canonical" href={canonical} /> : null}
{image ? <link href={image} /> : null}
{image ? <meta itemProp="image" content={image} /> : null}

<meta property="og:site_name" content="YOUR WEB SITE" />
<meta property="og:title" content={title} />
{description ? <meta property="og:description" content={description} /> : null}
{canonical ? <meta property="og:url" content={canonical} /> : null}
<meta property="og:locale" content={locales[lang]} />
<meta property="og:type" content={type} />
{image ? <meta property="og:image" content={image} /> : null}
{width ? <meta property="og:image:width" content={width} /> : null}
{height ? <meta property="og:image:height" content={height} /> : null}
<meta property="fb:pages" content="YOUR WEB SITE" />

{/* change type of twitter if there is no image? */}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={title} />
{description ? <meta name="twitter:description" content={description} /> : null}
{image ? <meta name="twitter:image" content={image} /> : null}
<meta name="twitter:site" content="@YOURWEBSITE" />
{canonical ? <link rel="alternate" href={data.canonical} hrefLang={lang} /> : null}
</>
);
};
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './Toast/Toast';
export * from './Accordion/Accordion';
export * from './CardList/CardList';
export * from './Pagination/Pagination';
export * from './Meta/Meta';
7 changes: 5 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type { NextPage } from 'next';
import Head from 'next/head';
import { HotRecipes, RandomRecipe } from 'components';
import { HotRecipes, Meta, RandomRecipe } from 'components';
import { media } from 'utils';
import { css } from '@emotion/react';

const Home: NextPage = () => {
const metaData = {
title: 'Home',
};
return (
<>
<Head>
<title>Home - HanSpoon</title>
<Meta data={metaData} />
</Head>
<div
css={css`
Expand Down