Skip to content

Commit

Permalink
update how metadata works
Browse files Browse the repository at this point in the history
  • Loading branch information
cesque committed Mar 5, 2024
1 parent 815f5a1 commit 12bb77c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 62 deletions.
14 changes: 0 additions & 14 deletions app/[slug]/head.js

This file was deleted.

6 changes: 6 additions & 0 deletions app/[slug]/layout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { getMetadata } from '@/utils/getMetadata'
export async function generateMetadata({ params: { slug }}) {
return getMetadata(slug, 'article')
}


export default function Layout({ children }) {
return <>
{ children }
Expand Down
11 changes: 0 additions & 11 deletions app/head.js

This file was deleted.

4 changes: 4 additions & 0 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import '@/styles/globals.scss'

import { getMetadata } from '@/utils/getMetadata'

export const metadata = getMetadata(null, 'website')

export default function Layout({ children }) {
return <html>
<body>
Expand Down
11 changes: 0 additions & 11 deletions app/~/[slug]/head.js

This file was deleted.

4 changes: 4 additions & 0 deletions app/~/[slug]/layout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { getMetadata } from '@/utils/getMetadata'

export const metadata = getMetadata(null, 'website')

export default function Layout({ children }) {
return <>
{ children }
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 15 additions & 26 deletions utils/getMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,26 @@ export function getMetadata(title, type) {

let url = process.env.VERCEL_URL ? `https://${ process.env.VERCEL_URL }` : `http://localhost:3000`

let meta = {
og: {
return {
title: pageTitle,
description: description,
icons: {
icon: '/favicon.svg',
},
openGraph: {
title: pageTitle,
description: description,
type: type,
image: `${ url }/api/og?${ imageParams.toString() }`,
'image:width': 1000,
'image:height': 500,
description: description
images: [{
url: `${ url }/api/og?${ imageParams.toString() }`,
width: 1000,
height: 500,
}],
},
twitter: {
card: 'summary_large_image',
site: '@cesque',
}
},
themeColor: '#000000',
}

return <>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
{
Object.keys(meta).map(section => {
return Object.keys(meta[section]).map(name => {
let content = meta[section][name]
let nameText = `${section}:${name}`

if(section == 'og') {
return <meta property={ nameText } content={ content } />
} else {
return <meta name={ nameText } content={ content } />
}
})
}).flat()
}
</>
}

0 comments on commit 12bb77c

Please sign in to comment.