Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #174 from otoyo/nextjs-13_2
Browse files Browse the repository at this point in the history
Migrate Nextjs 13.2
  • Loading branch information
otoyo authored Feb 26, 2023
2 parents 9a3f3f2 + 1c4dc0b commit 7497df0
Show file tree
Hide file tree
Showing 17 changed files with 338 additions and 176 deletions.
19 changes: 0 additions & 19 deletions app/blog/[slug]/head.tsx

This file was deleted.

38 changes: 37 additions & 1 deletion app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { Metadata } from 'next'
import { redirect } from 'next/navigation'
import { NEXT_PUBLIC_URL } from '../../server-constants'
import {
NEXT_PUBLIC_URL,
NEXT_PUBLIC_SITE_TITLE,
} from '../../server-constants'
import { Post } from '../../../lib/notion/interfaces'
import GoogleAnalytics from '../../../components/google-analytics'
import {
Expand All @@ -26,6 +30,38 @@ import {

export const revalidate = 30

export async function generateMetadata({ params }): Promise<Metadata> {
const post = await getPostBySlug(params.slug)
const title = `${post?.Title} - ${NEXT_PUBLIC_SITE_TITLE}`
const description = post?.Excerpt
const url = NEXT_PUBLIC_URL ? new URL(getBlogLink(post?.Slug || ''), NEXT_PUBLIC_URL) : undefined
const imageURL = new URL(`/api/og-image?slug=${post?.Slug}`, NEXT_PUBLIC_URL)

const metadata: Metadata = {
title: title,
description: description,
openGraph: {
title: title,
description: description,
url: url,
siteName: title,
type: 'website',
images: [{url: imageURL}],
},
twitter: {
card: 'summary_large_image',
title: title,
description: description,
images: [{url: imageURL}],
},
alternates: {
canonical: url,
},
}

return metadata
}

export async function generateStaticParams() {
const posts = await getAllPosts()
return posts.map(p => ({ slug: p.Slug }))
Expand Down
11 changes: 0 additions & 11 deletions app/blog/before/[date]/head.tsx

This file was deleted.

39 changes: 38 additions & 1 deletion app/blog/before/[date]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { Metadata } from 'next'
import { notFound } from 'next/navigation'
import { NUMBER_OF_POSTS_PER_PAGE } from '../../../../app/server-constants'
import {
NEXT_PUBLIC_URL,
NEXT_PUBLIC_SITE_TITLE,
NEXT_PUBLIC_SITE_DESCRIPTION,
NUMBER_OF_POSTS_PER_PAGE,
} from '../../../../app/server-constants'
import GoogleAnalytics from '../../../../components/google-analytics'
import {
getRankedPosts,
Expand All @@ -22,6 +28,37 @@ import styles from '../../../../styles/blog.module.css'

export const revalidate = 3600

export async function generateMetadata({ params: { date: encodedDate } }): Promise<Metadata> {
const date = decodeURIComponent(encodedDate)
const title = `Post before ${date.split('T')[0]} - ${NEXT_PUBLIC_SITE_TITLE}`
const description = NEXT_PUBLIC_SITE_DESCRIPTION
const url = NEXT_PUBLIC_URL ? new URL('/blog', NEXT_PUBLIC_URL) : undefined
const imageURL = new URL('/default.png', NEXT_PUBLIC_URL)

const metadata: Metadata = {
title: title,
openGraph: {
title: title,
description: description,
url: url,
siteName: title,
type: 'website',
images: [{url: imageURL}],
},
twitter: {
card: 'summary_large_image',
title: title,
description: description,
images: [{url: imageURL}],
},
alternates: {
canonical: url,
},
}

return metadata
}

const BlogBeforeDatePage = async ({ params: { date: encodedDate } }) => {
const date = decodeURIComponent(encodedDate)

Expand Down
7 changes: 0 additions & 7 deletions app/blog/head.tsx

This file was deleted.

38 changes: 37 additions & 1 deletion app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { NUMBER_OF_POSTS_PER_PAGE } from '../../app/server-constants'
import type { Metadata } from 'next'
import {
NEXT_PUBLIC_URL,
NEXT_PUBLIC_SITE_TITLE,
NEXT_PUBLIC_SITE_DESCRIPTION,
NUMBER_OF_POSTS_PER_PAGE,
} from '../../app/server-constants'
import GoogleAnalytics from '../../components/google-analytics'
import {
BlogPostLink,
Expand All @@ -21,6 +27,36 @@ import {

export const revalidate = 60

export async function generateMetadata(): Promise<Metadata> {
const title = `Blog - ${NEXT_PUBLIC_SITE_TITLE}`
const description = NEXT_PUBLIC_SITE_DESCRIPTION
const url = NEXT_PUBLIC_URL ? new URL('/blog', NEXT_PUBLIC_URL) : undefined
const imageURL = new URL('/default.png', NEXT_PUBLIC_URL)

const metadata: Metadata = {
title: title,
openGraph: {
title: title,
description: description,
url: url,
siteName: title,
type: 'website',
images: [{url: imageURL}],
},
twitter: {
card: 'summary_large_image',
title: title,
description: description,
images: [{url: imageURL}],
},
alternates: {
canonical: url,
},
}

return metadata
}

const BlogPage = async () => {
const [posts, firstPost, rankedPosts, tags] = await Promise.all([
getPosts(NUMBER_OF_POSTS_PER_PAGE),
Expand Down
12 changes: 0 additions & 12 deletions app/blog/tag/[tag]/before/[date]/head.tsx

This file was deleted.

40 changes: 39 additions & 1 deletion app/blog/tag/[tag]/before/[date]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { Metadata } from 'next'
import { notFound } from 'next/navigation'
import { NUMBER_OF_POSTS_PER_PAGE } from '../../../../../../app/server-constants'
import {
NEXT_PUBLIC_URL,
NEXT_PUBLIC_SITE_TITLE,
NEXT_PUBLIC_SITE_DESCRIPTION,
NUMBER_OF_POSTS_PER_PAGE,
} from '../../../../../../app/server-constants'
import GoogleAnalytics from '../../../../../../components/google-analytics'
import { colorClass } from '../../../../../../components/notion-block'
import {
Expand All @@ -25,6 +31,38 @@ import '../../../../../../styles/notion-color.css'

export const revalidate = 3600

export async function generateMetadata({ params: { date: encodedDate, tag: encodedTag } }): Promise<Metadata> {
const date = decodeURIComponent(encodedDate)
const tag = decodeURIComponent(encodedTag)
const title = `Posts in ${tag} before ${date.split('T')[0]} - ${NEXT_PUBLIC_SITE_TITLE}`
const description = NEXT_PUBLIC_SITE_DESCRIPTION
const url = NEXT_PUBLIC_URL ? new URL('/blog', NEXT_PUBLIC_URL) : undefined
const imageURL = new URL('/default.png', NEXT_PUBLIC_URL)

const metadata: Metadata = {
title: title,
openGraph: {
title: title,
description: description,
url: url,
siteName: title,
type: 'website',
images: [{url: imageURL}],
},
twitter: {
card: 'summary_large_image',
title: title,
description: description,
images: [{url: imageURL}],
},
alternates: {
canonical: url,
},
}

return metadata
}

const BlogTagBeforeDatePage = async ({ params: { tag: encodedTag, date: encodedDate } }) => {
const tag = decodeURIComponent(encodedTag)
const date = decodeURIComponent(encodedDate)
Expand Down
11 changes: 0 additions & 11 deletions app/blog/tag/[tag]/head.tsx

This file was deleted.

39 changes: 38 additions & 1 deletion app/blog/tag/[tag]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { Metadata } from 'next'
import { notFound } from 'next/navigation'
import { NUMBER_OF_POSTS_PER_PAGE } from '../../../../app/server-constants'
import {
NEXT_PUBLIC_URL,
NEXT_PUBLIC_SITE_TITLE,
NEXT_PUBLIC_SITE_DESCRIPTION,
NUMBER_OF_POSTS_PER_PAGE,
} from '../../../../app/server-constants'
import GoogleAnalytics from '../../../../components/google-analytics'
import {
BlogPostLink,
Expand All @@ -24,6 +30,37 @@ import '../../../../styles/notion-color.css'

export const revalidate = 60

export async function generateMetadata({ params: { tag: encodedTag } }): Promise<Metadata> {
const tag = decodeURIComponent(encodedTag)
const title = `Posts in ${tag} - ${NEXT_PUBLIC_SITE_TITLE}`
const description = NEXT_PUBLIC_SITE_DESCRIPTION
const url = NEXT_PUBLIC_URL ? new URL('/blog', NEXT_PUBLIC_URL) : undefined
const imageURL = new URL('/default.png', NEXT_PUBLIC_URL)

const metadata: Metadata = {
title: title,
openGraph: {
title: title,
description: description,
url: url,
siteName: title,
type: 'website',
images: [{url: imageURL}],
},
twitter: {
card: 'summary_large_image',
title: title,
description: description,
images: [{url: imageURL}],
},
alternates: {
canonical: url,
},
}

return metadata
}

export async function generateStaticParams() {
const tags = await getAllTags()
return tags.map(tag => ({ tag: tag.name }))
Expand Down
7 changes: 0 additions & 7 deletions app/head.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import {
NEXT_PUBLIC_SITE_TITLE,
NEXT_PUBLIC_SITE_DESCRIPTION,
} from './server-constants'
import Header from '../components/header'
import Footer from '../components/footer'
import '../styles/global.css'
import '../styles/syntax-coloring.css'
import styles from '../styles/shared.module.css'

export const metadata = {
title: NEXT_PUBLIC_SITE_TITLE,
description: NEXT_PUBLIC_SITE_DESCRIPTION,
}

const RootLayout = ({
children,
}: {
Expand Down
36 changes: 35 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
import type { Metadata } from 'next'
import Link from 'next/link'
import { NEXT_PUBLIC_SITE_TITLE } from './server-constants'
import {
NEXT_PUBLIC_URL,
NEXT_PUBLIC_SITE_TITLE,
NEXT_PUBLIC_SITE_DESCRIPTION
} from './server-constants'
import GoogleAnalytics from '../components/google-analytics'
import styles from '../styles/page.module.css'

export async function generateMetadata(): Promise<Metadata> {
const title = NEXT_PUBLIC_SITE_TITLE
const description = NEXT_PUBLIC_SITE_DESCRIPTION
const url = NEXT_PUBLIC_URL ? new URL(NEXT_PUBLIC_URL) : undefined
const imageURL = new URL('/default.png', NEXT_PUBLIC_URL)

const metadata: Metadata = {
openGraph: {
title: title,
description: description,
url: url,
siteName: title,
type: 'website',
images: [{url: imageURL}],
},
twitter: {
card: 'summary_large_image',
title: title,
description: description,
images: [{url: imageURL}],
},
alternates: {
canonical: url,
},
}

return metadata
}

const RootPage = () => (
<>
<GoogleAnalytics pageTitle={NEXT_PUBLIC_SITE_TITLE} />
Expand Down
1 change: 1 addition & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
Loading

1 comment on commit 7497df0

@vercel
Copy link

@vercel vercel bot commented on 7497df0 Feb 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

easy-notion-blog – ./

easy-notion-blog-otoyo.vercel.app
my-notion-blog-seven.vercel.app
easy-notion-blog-git-main-otoyo.vercel.app

Please sign in to comment.