-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor page.tsx to use single quotes and update metadata generation
- Loading branch information
Showing
1 changed file
with
60 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,69 @@ | ||
import options from "@/lib/options"; | ||
import { Metadata, ResolvingMetadata } from "next"; | ||
import Main from "./Main"; | ||
import options from '@/lib/options'; | ||
import { Metadata, ResolvingMetadata } from 'next'; | ||
import Main from './Main'; | ||
|
||
type Props = { | ||
params: { type: string; id: number }; | ||
params: { type: string; id: number }; | ||
}; | ||
|
||
export async function getStaticPaths() { | ||
return { | ||
paths: [], // no pre-rendered pages | ||
fallback: 'blocking', // generate pages on-demand | ||
}; | ||
} | ||
|
||
export async function getStaticProps({ params }) { | ||
// Fetch data based on `id` and `type` | ||
const data = await fetchData(params.id, params.type); | ||
|
||
return { | ||
props: { | ||
data, | ||
}, | ||
revalidate: 60, // regenerate the page every 60 seconds | ||
}; | ||
} | ||
|
||
export async function generateMetadata({ params }: Props, parent: ResolvingMetadata): Promise<Metadata> { | ||
// read route params | ||
const id = params.id; | ||
const type = params.type; | ||
|
||
// fetch data | ||
const content = await fetch(`https://api.themoviedb.org/3/${type}/${id}?language=en-US`, options).then((res) => res.json()); | ||
|
||
// fetch keywords | ||
const keywords = await fetch(`https://api.themoviedb.org/3/${type}/${id}/keywords?language=en-US`, options).then((res) => res.json()); | ||
let keywordsArray = []; | ||
if (keywords.results) { | ||
for (let i = 0; i < keywords.results.length; i++) { | ||
keywordsArray.push(keywords.results[i].name); | ||
} | ||
} else { | ||
for (let i = 0; i < keywords.keywords.length; i++) { | ||
keywordsArray.push(keywords.keywords[i].name); | ||
} | ||
} | ||
|
||
// get image url from | ||
const image = content.backdrop_path || content.poster_path; | ||
|
||
export async function generateMetadata( | ||
{ params }: Props, | ||
parent: ResolvingMetadata, | ||
): Promise<Metadata> { | ||
// read route params | ||
const id = params.id; | ||
const type = params.type; | ||
|
||
// fetch data | ||
const content = await fetch( | ||
`https://api.themoviedb.org/3/${type}/${id}?language=en-US`, | ||
options, | ||
).then((res) => res.json()); | ||
|
||
// fetch keywords | ||
const keywords = await fetch( | ||
`https://api.themoviedb.org/3/${type}/${id}/keywords?language=en-US`, | ||
options, | ||
).then((res) => res.json()); | ||
let keywordsArray = []; | ||
if (keywords.results) { | ||
for (let i = 0; i < keywords.results.length; i++) { | ||
keywordsArray.push(keywords.results[i].name); | ||
} | ||
} else { | ||
for (let i = 0; i < keywords.keywords.length; i++) { | ||
keywordsArray.push(keywords.keywords[i].name); | ||
} | ||
} | ||
|
||
// get image url from | ||
const image = content.backdrop_path || content.poster_path; | ||
|
||
return { | ||
title: `WatchWave`, | ||
keywords: | ||
"watch movies, movies online, watch TV, TV online, TV shows online, watch TV shows, stream movies, stream tv, instant streaming, watch online, movies, watch movies United States, watch TV online, no download, full length movies watch online, movies online, movies, watch movies online, watch movies, watch movies online free, watch movies for free, watch streaming media, watch tv online, watch movies online, watch movies online free, watch movies for free, watch streaming media, watch tv online, " + | ||
keywordsArray.join(", "), | ||
description: `${content.overview}`, | ||
openGraph: { | ||
type: "website", | ||
url: `https://watchwave.github.io/watch/${type}/${id}`, | ||
title: `Watch ${content.title || content.name} for free on WatchWave`, | ||
images: [image && { url: `https://image.tmdb.org/t/p/w1280${image}` }], | ||
}, | ||
}; | ||
return { | ||
title: `WatchWave`, | ||
keywords: | ||
'watch movies, movies online, watch TV, TV online, TV shows online, watch TV shows, stream movies, stream tv, instant streaming, watch online, movies, watch movies United States, watch TV online, no download, full length movies watch online, movies online, movies, watch movies online, watch movies, watch movies online free, watch movies for free, watch streaming media, watch tv online, watch movies online, watch movies online free, watch movies for free, watch streaming media, watch tv online, ' + | ||
keywordsArray.join(', '), | ||
description: `${content.overview}`, | ||
openGraph: { | ||
type: 'website', | ||
url: `https://watchwave.github.io/watch/${type}/${id}`, | ||
title: `Watch ${content.title || content.name} for free on WatchWave`, | ||
images: [image && { url: `https://image.tmdb.org/t/p/w1280${image}` }], | ||
}, | ||
}; | ||
} | ||
|
||
export default function Page({ params }: Props) { | ||
return <Main params={params} />; | ||
return <Main params={params} />; | ||
} |