I have been trying to generate RSS feed for my website. Although it perfectly works in the dev environment, the xml file is not generated when building for production.
Since I have created some json files in the same way and those are properly generated, I suspect xml.ts format might not be regarded as the build target.
Does anyone know the solution?
source code (src/routes/rss.xml.ts)
import { getPosts } from '../lib/posts/getPosts';
const xml = (posts: postMeta[]) => `<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:atom="https://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>Kota Yatagai</title>
<link>https://kota-yata.com</link>
<description><![CDATA[Personal Blog & Stuffs by Kota Yatagai]]></description>
${posts.map(
post => `
<item>
<title><![CDATA[${post.meta.title}]]></title>
<description><![CDATA[${post.meta.description}]]></description>
<category>${post.meta.category}</category>
<link>https://kota-yata.com/posts/${post.path}</link>
<guid isPermaLink="true">https://kota-yata.com/posts/${post.path}</guid>
<pubDate><![CDATA[ ${post.meta.date}]]></pubDate>
<enclosure url="${post.meta.ogp || `https://kota-yata.com/ogp.webp`}" length="0" type="image/webp"/>
<dc:creator>Kota Yatagai</dc:creator>
</item>
`
).join('')}
</channel>
</rss>`;
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const get = () => {
const headers = {
'Cache-Control': 'max-age=0, s-maxage=600',
'Content-Type': 'application/xml',
};
const posts = getPosts();
const body = xml(posts);
return { body, headers };
};
svelte.config.js (just in case)
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: null
})
},
};
export default config;