Skip to content

Commit

Permalink
feat: add dynamic og from defaultMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSuperDev authored and theodorusclarence committed Oct 10, 2021
1 parent 782756b commit de1607b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/Seo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Head from 'next/head';
import { useRouter } from 'next/router';

import { openGraph } from '@/lib/helper';

const defaultMeta = {
title: 'Next.js + Tailwind CSS + TypeScript Starter',
site_name: 'Next.js + Tailwind CSS + TypeScript Starter',
Expand All @@ -11,6 +13,7 @@ const defaultMeta = {
type: 'website',
robots: 'follow, index',
};
defaultMeta.image = openGraph(defaultMeta.title, defaultMeta.description);

type SeoProps = {
date?: string;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function classNames(...classes: string[]): string {
return classes.filter(Boolean).join(' ');
}

export function openGraph(title: string, description: string): string {
const ogTitle = encodeURIComponent(title.trim());
const ogDesc = encodeURIComponent(description.trim());
return `https://thcl.dev/og?title=${ogTitle}&description=${ogDesc}`;
}

0 comments on commit de1607b

Please sign in to comment.