site: fix invalid blog rss feed (#2085) and tidy

pull/2087/head
Conduitry 6 years ago
parent d61616e148
commit f262293135

@ -1,10 +1,10 @@
import get_posts from '../api/blog/_posts.js'; import get_posts from '../api/blog/_posts.js';
const months = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split( ',' ); const months = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(',');
function formatPubdate ( str ) { function formatPubdate(str) {
const [ y, m, d ] = str.split( '-' ); const [y, m, d] = str.split('-');
return `${d} ${months[+m]} ${y}`; return `${d} ${months[+m]} ${y} 12:00 +0000`;
} }
const rss = ` const rss = `
@ -20,18 +20,18 @@ const rss = `
<title>Svelte</title> <title>Svelte</title>
<link>https://svelte.technology/blog</link> <link>https://svelte.technology/blog</link>
</image> </image>
${get_posts().map( post => ` ${get_posts().map(post => `
<item> <item>
<title>${post.metadata.title}</title> <title>${post.metadata.title}</title>
<link>https://svelte.technology/blog/${post.slug}</link> <link>https://svelte.technology/blog/${post.slug}</link>
<description>${post.metadata.description}</description> <description>${post.metadata.description}</description>
<pubDate>${formatPubdate(post.metadata.pubdate)}</pubDate> <pubDate>${formatPubdate(post.metadata.pubdate)}</pubDate>
</item> </item>
` )} `).join('')}
</channel> </channel>
</rss> </rss>
`.replace( />[^\S]+/gm, '>' ).replace( /[^\S]+</gm, '<' ).trim(); `.replace(/>[^\S]+/gm, '>').replace(/[^\S]+</gm, '<').trim();
export function get(req, res) { export function get(req, res) {
res.set({ res.set({
@ -39,4 +39,4 @@ export function get(req, res) {
'Content-Type': 'application/rss+xml' 'Content-Type': 'application/rss+xml'
}); });
res.end(rss); res.end(rss);
} }

Loading…
Cancel
Save