// rss.js // https://cmswp.gwkbali.com/wp-json/wp/v2/monthly-release // https://cmswp.gwkbali.com/wp-json/wp/v2/mediacorner import { Feed } from 'feed' import { format } from 'date-fns' const generateRssFeed = async (posts) => { const feed = new Feed({ title: 'GWK Cultural Park - Bali', description: 'The Ultimate Destination for Those Seeking an Immersive Cultural Experience in Bali!', id: 'https://www.gwkbali.com', link: 'https://www.gwkbali.com', language: 'en', image: 'https://www.gwkbali.com/images/logogwk.svg', favicon: 'https://www.gwkbali.com/favicon/favicon.ico', // author: { // name: "John Doe", // email: "john@example.com", // link: "http://localhost:3000/about", // }, }) posts.forEach((post) => { feed.addItem({ title: post.title, description: post.excerpt, id: post.link, url: post.link, date: new Date(), }) }) return feed.rss2() } const Rss = () => {} export async function getServerSideProps({ res }) { //const { slug } = mediacorner const response = await fetch( `https://cmswp.gwkbali.com/wp-json/wp/v2/mediacorner` ) const data = await response.json() //const posts = [data] //console.log(data) const posts = [ data, // { // title: 'Post One', // description: 'This is the first post', // url: 'http://localhost:3000/posts/1', // date: new Date(), // }, // { // title: 'Post Two', // description: 'This is the second post', // url: 'http://localhost:3000/posts/2', // date: new Date(), // }, // { // title: 'Post Three', // description: 'This is the third post', // url: 'http://localhost:3000/posts/3', // date: new Date(), // }, ] const rss = await generateRssFeed(posts) res.setHeader('Content-Type', 'text/xml') res.write(rss) res.end() return { props: {} } } export default Rss