I want to generate a dynamic sitemap but it is showing undefined value for the post.frontmatter.title, what shall I do to fix this?
Code for sitemap.xml.js,
import { Feed } from "feed"; import { getAllPosts } from "../lib/posts"; export async function get(){ const feed = new Feed({ title: "dhairyashah.vercel.app", description: "I am 16 years old and I share and write articles on Web Development, Programming, and Technology.", id: "https://dhairyashah.vercel.app/", link: "https://dhairyashah.vercel.app/sitemap.xml", language: "en", image: "https://dhairyashah.vercel.app/assets/profile-pic.png", favicon: "https://dhairyashah.vercel.app/assets/profile-pic.png", author: { name: "Dhairya Shah", email: "[email protected]", }, feedLinks: { rss: "https://dhairyashah.vercel.app/sitemap.xml", atom: "https://dhairyashah.vercel.app/sitemap.xml", }, }) const allPosts = (await getAllPosts()) allPosts.forEach((post) => { feed.addItem({ title: post.frontmatter.title, id: `https://dhairyashah.vercel.app/posts/${post.url}`, link: `https://dhairyashah.vercel.app/posts/${post.url}`, content: post.frontmatter.description, }); }) return { body: feed.rss2() } } Code for ../lib/posts.js,
async function load() { const fetchedPosts = import.meta.glob('../pages/posts/*.mdx', { eager: true }); const getPost = async (key) => { const url = key.replace('../pages/posts/', '/').replace('.mdx', '/'); const awaitedPost = await fetchedPosts[key].default(); const item = { ...awaitedPost.props.frontmatter, url, key, } return item; }; const mappedPosts = Object.keys(fetchedPosts).map((key) => { const awaitedPost = getPost(key); return awaitedPost; }); const results = await Promise.all(mappedPosts); return results; } let _posts; export async function getAllPosts() { _posts = _posts || load(); return await _posts; } What can be do so that I can generate the site map without getting undefined error?

post.titleinstead? Since you're using the spread operator onprop.frontmatteryou should be able to accesstitledirectly.