Skip to content

Commit aa18988

Browse files
feat: change RSS feed pubDate and items order (sveltejs#1077)
* feat: render day of week in RSS pubDate * feat: sort rss feed by date desc * Apply suggestions from code review * simplify --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 13a0f50 commit aa18988

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

apps/svelte.dev/src/routes/blog/rss.xml/+server.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ import { render_content } from '$lib/server/renderer';
33

44
export const prerender = true;
55

6-
const months = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(',');
7-
8-
/** @param {string} str */
9-
function formatPubdate(str) {
10-
const [y, m, d] = str.split('-');
11-
return `${d} ${months[+m]} ${y} 12:00 +0000`;
12-
}
13-
146
/** @param {string} html */
157
function escapeHTML(html) {
168
/** @type {{ [key: string]: string }} */
@@ -30,14 +22,15 @@ const get_rss = async (posts) => {
3022
const renderedPosts = await Promise.all(
3123
posts
3224
.filter((post) => !post.metadata.draft)
25+
.reverse()
3326
.map(
3427
async (post) => `
3528
<item>
3629
<title>${escapeHTML(post.metadata.title)}</title>
3730
<link>https://svelte.dev/${post.slug}</link>
3831
<author>${escapeHTML(post.metadata.author)}</author>
3932
<description>${escapeHTML(await render_content(post.file, post.body))}</description>
40-
<pubDate>${formatPubdate(/** @type {string} */ (post.file.split('/').pop()).slice(0, 10))}</pubDate>
33+
<pubDate>${new Date(/** @type {string} */ (post.file.split('/').pop()).slice(0, 10)).toUTCString()}</pubDate>
4134
</item>
4235
`
4336
)

0 commit comments

Comments
 (0)