Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline compilation of html #2345

Closed
btakita opened this issue Mar 30, 2019 · 2 comments
Closed

inline compilation of html #2345

btakita opened this issue Mar 30, 2019 · 2 comments

Comments

@btakita
Copy link
Contributor

btakita commented Mar 30, 2019

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);
}
@Rich-Harris
Copy link
Member

Not quite sure I understand the value of this proposal?

@Conduitry
Copy link
Member

I don't think this is something we want to facilitate. You should just be compiling in SSR mode (at bundle time) and using that at runtime. If you need to have some sort of runtime compilation of components, you'll need to bring your own (runtime) bundler and set up the sandbox in the particular way that you need it, etc. We don't want to be in the business of blessing what is essentially a server-side eval or worrying about exposing the right things or worrying about keeping people safe. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants