initial commit
This commit is contained in:
162
app/sitemap.ts
Normal file
162
app/sitemap.ts
Normal file
@@ -0,0 +1,162 @@
|
||||
import { MetadataRoute } from 'next'
|
||||
import TopicModel from '@/models/topic'
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:4023'
|
||||
|
||||
// Static pages
|
||||
const staticPages = [
|
||||
{
|
||||
url: baseUrl,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily' as const,
|
||||
priority: 1,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/about`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly' as const,
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/services`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.9,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/services/cloud-instance`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/services/hosting-control-panel`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/services/kubernetes`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/services/vpn`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/services/human-developer`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/tools`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.7,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/tools/speech-to-text`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly' as const,
|
||||
priority: 0.6,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/contact`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly' as const,
|
||||
priority: 0.7,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/topics`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily' as const,
|
||||
priority: 0.8,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/search`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily' as const,
|
||||
priority: 0.7,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/feedback`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly' as const,
|
||||
priority: 0.6,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/auth`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly' as const,
|
||||
priority: 0.5,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/terms`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'yearly' as const,
|
||||
priority: 0.3,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/privacy`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'yearly' as const,
|
||||
priority: 0.3,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/legal-agreement`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'yearly' as const,
|
||||
priority: 0.3,
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/refund-policy`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'yearly' as const,
|
||||
priority: 0.3,
|
||||
},
|
||||
]
|
||||
|
||||
// Dynamic topic pages
|
||||
let topicPages: MetadataRoute.Sitemap = []
|
||||
let tagPages: MetadataRoute.Sitemap = []
|
||||
|
||||
try {
|
||||
// Get published topic posts
|
||||
const topics = await TopicModel.find({ isDraft: false })
|
||||
.select('slug publishedAt updatedAt')
|
||||
.lean()
|
||||
|
||||
topicPages = topics.map((topic) => ({
|
||||
url: `${baseUrl}/topics/${topic.slug}`,
|
||||
lastModified: new Date(topic.publishedAt),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.6,
|
||||
}))
|
||||
|
||||
// Get unique tags from all topics
|
||||
const allTopics = await TopicModel.find({ isDraft: false }).select('tags').lean()
|
||||
|
||||
const tagsSet = new Set<string>()
|
||||
allTopics.forEach((topic) => {
|
||||
topic.tags?.forEach((tag) => tagsSet.add(tag.name))
|
||||
})
|
||||
|
||||
tagPages = Array.from(tagsSet).map((tagName) => ({
|
||||
url: `${baseUrl}/topics?tag=${encodeURIComponent(tagName)}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.5,
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error('Error generating dynamic sitemap entries:', error)
|
||||
// Continue with static pages only if database is unavailable
|
||||
}
|
||||
|
||||
return [...staticPages, ...topicPages, ...tagPages]
|
||||
}
|
||||
Reference in New Issue
Block a user