feat: Implement Phase 2 features including blog, collections, saved listings, manifest, and api cron sync
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { mockDb } from '@/lib/mockDb'
|
||||
|
||||
export async function GET() {
|
||||
const baseUrl = 'https://marmarislocal.com'
|
||||
|
||||
// Fetch data
|
||||
const posts = await mockDb.getBlogPosts(true)
|
||||
const listings = await mockDb.getListings({ isLocalApproved: true })
|
||||
|
||||
// Construct XML
|
||||
let xml = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>Marmaris Local</title>
|
||||
<link>${baseUrl}</link>
|
||||
<description>Marmaris'in yerel rehberi, gurme mekanları ve gezilecek gizli yerleri.</description>
|
||||
<language>tr</language>
|
||||
<lastBuildDate>${new Date().toUTCString()}</lastBuildDate>
|
||||
<atom:link href="${baseUrl}/feed.xml" rel="self" type="application/rss+xml" />
|
||||
`
|
||||
|
||||
// Add blog posts
|
||||
for (const post of posts.slice(0, 10)) {
|
||||
const pubDate = post.publishedAt ? new Date(post.publishedAt).toUTCString() : new Date(post.createdAt).toUTCString()
|
||||
xml += ` <item>
|
||||
<title><![CDATA[${post.titleTr}]]></title>
|
||||
<link>${baseUrl}/tr/blog/${post.slug}</link>
|
||||
<guid>${baseUrl}/tr/blog/${post.slug}</guid>
|
||||
<pubDate>${pubDate}</pubDate>
|
||||
<description><![CDATA[${post.contentTr.substring(0, 200)}...]]></description>
|
||||
</item>
|
||||
`
|
||||
}
|
||||
|
||||
// Add newly added approved listings
|
||||
for (const listing of listings.slice(0, 10)) {
|
||||
const pubDate = new Date(listing.createdAt).toUTCString()
|
||||
const catSlug = listing.category?.slug || 'isletmeler'
|
||||
xml += ` <item>
|
||||
<title><![CDATA[Yeni Onaylandı: ${listing.nameTr} (${listing.neighborhood?.nameTr})]]></title>
|
||||
<link>${baseUrl}/tr/${catSlug}/${listing.slug}</link>
|
||||
<guid>${baseUrl}/tr/${catSlug}/${listing.slug}</guid>
|
||||
<pubDate>${pubDate}</pubDate>
|
||||
<description><![CDATA[${listing.descriptionTr}]]></description>
|
||||
</item>
|
||||
`
|
||||
}
|
||||
|
||||
xml += `</channel>
|
||||
</rss>`
|
||||
|
||||
return new Response(xml, {
|
||||
headers: {
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate=43200'
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user