Skip to content

Commit 8496cea

Browse files
committed
refactor(sitemap): simplify sitemap generation by removing unused route handling and enhancing high-value page entries
1 parent 722ff22 commit 8496cea

File tree

3 files changed

+25
-98
lines changed

3 files changed

+25
-98
lines changed

src/routes/blog.index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { LibrariesWidget } from '~/components/LibrariesWidget'
1515
import { partners } from '~/utils/partners'
1616
import { PartnersRail, RightRail } from '~/components/RightRail'
1717
import { RecentPostsWidget } from '~/components/RecentPostsWidget'
18-
import { seo } from '~/utils/seo'
1918

2019
type BlogFrontMatter = {
2120
slug: string
@@ -61,10 +60,11 @@ export const Route = createFileRoute('/blog/')({
6160
notFoundComponent: () => <PostNotFound />,
6261
component: BlogIndex,
6362
head: () => ({
64-
meta: seo({
65-
title: 'Blog | TanStack',
66-
description: 'The latest news and blog posts from TanStack.',
67-
}),
63+
meta: [
64+
{
65+
title: 'Blog',
66+
},
67+
],
6868
}),
6969
})
7070

src/routes/libraries.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import * as React from 'react'
33
import { libraries, Library } from '~/libraries'
44
import { reactChartsProject } from '~/libraries/react-charts'
55
import LibraryCard from '~/components/LibraryCard'
6-
import { seo } from '~/utils/seo'
76

87
export const Route = createFileRoute('/libraries')({
98
component: LibrariesPage,
109
head: () => ({
11-
meta: seo({
12-
title: 'All Libraries - TanStack',
13-
description: 'Browse all TanStack libraries.',
14-
}),
10+
meta: [
11+
{
12+
title: 'All Libraries - TanStack',
13+
},
14+
{
15+
name: 'description',
16+
content: 'Browse all TanStack libraries.',
17+
},
18+
],
1519
}),
1620
})
1721

src/utils/sitemap.ts

Lines changed: 11 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,23 @@ import { fetchRepoDirectoryContents } from '~/utils/docs'
55
import type { GitHubFileNode } from '~/utils/documents.server'
66
import { env } from '~/utils/env'
77

8-
const TOP_LEVEL_ROUTE_MODULES = Object.keys(
9-
import.meta.glob('../routes/*.{ts,tsx}'),
10-
)
11-
12-
const TOP_LEVEL_INDEX_ROUTE_MODULES = Object.keys(
13-
import.meta.glob('../routes/*/index.tsx'),
14-
)
15-
168
export type SitemapEntry = {
179
path: string
1810
lastModified?: string
1911
}
2012

2113
const MAX_DOCS_SITEMAP_DEPTH = 3
2214

23-
const EXCLUDED_TOP_LEVEL_ROUTE_NAMES = new Set([
24-
'__root',
25-
'account',
26-
'ads',
27-
'blog.$',
28-
'brand-guide',
29-
'builder.docs',
30-
'dashboard',
31-
'feed',
32-
'feedback-leaderboard',
33-
'llms.txt',
34-
'login',
35-
'merch',
36-
'partners-embed',
37-
'privacy',
38-
'terms',
39-
'robots.txt',
40-
'rss.xml',
41-
'sitemap.xml',
42-
'sponsors-embed',
43-
])
44-
45-
const EXCLUDED_TOP_LEVEL_ROUTE_DIRECTORIES = new Set([
46-
'$libraryId',
47-
'[.]well-known',
48-
'account',
49-
'admin',
50-
'stats',
51-
])
15+
const HIGH_VALUE_NON_DOC_PAGES = [
16+
'/',
17+
'/blog',
18+
'/libraries',
19+
'/learn',
20+
'/showcase',
21+
'/support',
22+
'/workshops',
23+
'/paid-support',
24+
] as const satisfies ReadonlyArray<string>
5225

5326
function trimTrailingSlash(url: string) {
5427
return url.replace(/\/$/, '')
@@ -67,56 +40,6 @@ function asLastModified(value: string) {
6740
return new Date(`${value}T12:00:00.000Z`).toISOString()
6841
}
6942

70-
function normalizeRouteName(routeName: string) {
71-
return routeName.replace(/\[\.\]/g, '.')
72-
}
73-
74-
function getTopLevelRoutePath(routeName: string) {
75-
if (routeName === 'index') {
76-
return '/'
77-
}
78-
79-
if (routeName.endsWith('.index')) {
80-
return `/${routeName.slice(0, -'.index'.length)}`
81-
}
82-
83-
return `/${routeName}`
84-
}
85-
86-
function getTopLevelEntries(): Array<SitemapEntry> {
87-
const fileEntries = TOP_LEVEL_ROUTE_MODULES.flatMap((modulePath) => {
88-
const routeName = normalizeRouteName(
89-
modulePath
90-
.split('/')
91-
.at(-1)
92-
?.replace(/\.(ts|tsx)$/, '') ?? '',
93-
)
94-
95-
if (!routeName || EXCLUDED_TOP_LEVEL_ROUTE_NAMES.has(routeName)) {
96-
return []
97-
}
98-
99-
return [{ path: getTopLevelRoutePath(routeName) }]
100-
})
101-
102-
const directoryEntries = TOP_LEVEL_INDEX_ROUTE_MODULES.flatMap(
103-
(modulePath) => {
104-
const routeDirectory = modulePath.split('/').at(-2)
105-
106-
if (
107-
!routeDirectory ||
108-
EXCLUDED_TOP_LEVEL_ROUTE_DIRECTORIES.has(routeDirectory)
109-
) {
110-
return []
111-
}
112-
113-
return [{ path: `/${normalizeRouteName(routeDirectory)}` }]
114-
},
115-
)
116-
117-
return [...fileEntries, ...directoryEntries]
118-
}
119-
12043
function getLibraryEntries(): Array<SitemapEntry> {
12144
return libraries.flatMap((library) => {
12245
if (
@@ -213,7 +136,7 @@ export async function getSitemapEntries(): Promise<Array<SitemapEntry>> {
213136
)
214137

215138
const entries = [
216-
...getTopLevelEntries(),
139+
...HIGH_VALUE_NON_DOC_PAGES.map((path) => ({ path })),
217140
...getLibraryEntries(),
218141
...docsEntries.flat(),
219142
...getBlogEntries(),

0 commit comments

Comments
 (0)