-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Description
One advantage that react has over svelte is the ability to compile in a function. It would be nice if svelte could do the same.
Instead of manipulating a string in:
https://github.com/sveltejs/svelte.technology/blob/master/src/routes/blog/rss.xml.js
something like the following could be used:
import get_posts from '../api/blog/_posts.js';
import { interpret, deindent } from 'svelte/interpreter'
const months = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split( ',' );
function formatPubdate ( str ) {
const [ y, m, d ] = str.split( '-' );
return `${d} ${months[+m]} ${y}`;
}
const rss = interpret({post, formatPubdate, get_posts}, deindent`
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Svelte blog</title>
<link>https://svelte.technology/blog</link>
<description>News and information about the magical disappearing UI framework</description>
<image>
<url>https://svelte.technology/favicon.png</url>
<title>Svelte</title>
<link>https://svelte.technology/blog</link>
</image>
{#each get_posts() as post}
<item>
<title>{post.metadata.title}</title>
<link>https://svelte.technology/blog/{post.slug}</link>
<description>{post.metadata.description}</description>
<pubDate>{formatPubdate(post.metadata.pubdate)}</pubDate>
</item>
{/each}
</channel>
</rss>
`)
export function get(req, res) {
res.set({
'Cache-Control': `max-age=${30 * 60 * 1e3}`,
'Content-Type': 'application/rss+xml'
});
res.end(rss);
}Conduitry
Metadata
Metadata
Assignees
Labels
No labels