Skip to content

Commit 333b16a

Browse files
committed
Update sitemap
1 parent 2f438e0 commit 333b16a

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/app/blog/[slug]/helpers.ts

+14
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ export function formatDate(date: string) {
3030
timeZone: 'UTC',
3131
})
3232
}
33+
34+
export async function getPosts() {
35+
const {
36+
blogIndex: { blogPosts },
37+
} = await basehub({ cache: 'no-store' }).query({
38+
blogIndex: {
39+
blogPosts: {
40+
__args: { filter: { isPublished: true } },
41+
items: { _slug: true, _sys: { lastModifiedAt: true } },
42+
},
43+
},
44+
})
45+
return blogPosts.items
46+
}

src/app/blog/[slug]/page.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { formatDate, getPostBySlug } from '@/app/blog/[slug]/helpers'
1+
import { formatDate, getPostBySlug, getPosts } from '@/app/blog/[slug]/helpers'
22
import { TrackPage } from '@/components/track-page'
33
import { Button } from '@/components/ui/button'
4-
import { basehub } from 'basehub'
54
import { RichText } from 'basehub/react'
65
import { ArrowLeft } from 'lucide-react'
76
import type { Metadata } from 'next'
@@ -13,13 +12,8 @@ export const revalidate = 60
1312
export const dynamic = 'force-static'
1413

1514
export async function generateStaticParams() {
16-
const {
17-
blogIndex: { blogPosts },
18-
} = await basehub({ cache: 'no-store' }).query({
19-
blogIndex: { blogPosts: { items: { _slug: true } } },
20-
})
21-
22-
return blogPosts.items.map((blogPost) => ({ slug: blogPost._slug }))
15+
const posts = await getPosts()
16+
return posts.map(({ _slug }) => ({ slug: _slug }))
2317
}
2418

2519
export async function generateMetadata({

src/app/sitemap.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1+
import { getPosts } from '@/app/blog/[slug]/helpers'
12
import { env } from '@/lib/env'
23
import { MetadataRoute } from 'next'
34

4-
export default function sitemap(): MetadataRoute.Sitemap {
5+
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
6+
const posts = await getPosts()
57
return [
68
{
79
url: env.NEXT_PUBLIC_BASE_URL,
810
lastModified: new Date(),
911
changeFrequency: 'yearly',
1012
priority: 1,
1113
},
14+
{
15+
url: `${env.NEXT_PUBLIC_BASE_URL}/blog`,
16+
lastModified: new Date(),
17+
changeFrequency: 'yearly',
18+
priority: 1,
19+
},
20+
...posts.map(
21+
(post) =>
22+
({
23+
url: `${env.NEXT_PUBLIC_BASE_URL}/blog/${post._slug}`,
24+
lastModified: new Date(post._sys.lastModifiedAt),
25+
changeFrequency: 'yearly',
26+
priority: 1,
27+
}) as const,
28+
),
1229
]
1330
}

0 commit comments

Comments
 (0)