Skip to content

Commit

Permalink
chore: meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zce committed Feb 6, 2024
1 parent 9407e42 commit 388cc98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 3 additions & 2 deletions docs/guide/using-mdx.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export const MDXContent = ({ code, components }: MdxProps) => {
`./pages/posts/[slug].tsx`:

```jsx
import { posts } from '@/.velite'
import { MDXContent } from '@/components/mdx-content'

export default async function Post({ params: { slug } }) {
const post = await getPostBySlug(slug)
export default function Post({ params: { slug } }) {
const post = posts.find(i => i.slug === slug)
return (
<article>
<h1>{post.title}</h1>
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/with-nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ Then you can use it like this:
```tsx
import Link from 'next/link'

import { options } from '@/.velite'

const Post = async () => {
const options = await getOptions()
return (
<div>
{/* typed route */}
Expand Down
18 changes: 8 additions & 10 deletions examples/nextjs/app/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@ import { pages } from '#site/content'

import type { Metadata } from 'next'

interface PageProps {
type Props = {
params: {
slug: string
}
}

async function getPageBySlug(slug: string) {
function getPageBySlug(slug: string) {
return pages.find(page => page.slug === slug)
}

export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const page = await getPageBySlug(params.slug)
export function generateMetadata({ params }: Props): Metadata {
const page = getPageBySlug(params.slug)
if (page == null) return {}
return { title: page.title }
}

export async function generateStaticParams(): Promise<PageProps['params'][]> {
return pages.map(page => ({
slug: page.slug
}))
export function generateStaticParams(): Props['params'][] {
return pages.map(page => ({ slug: page.slug }))
}

export default async function PagePage({ params }: PageProps) {
const page = await getPageBySlug(params.slug)
export default function PagePage({ params }: Props) {
const page = getPageBySlug(params.slug)

if (page == null) notFound()

Expand Down

0 comments on commit 388cc98

Please sign in to comment.