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

Add XML generation #461

Open
aubergene opened this issue Oct 2, 2018 · 3 comments

Comments

@aubergene
Copy link
Contributor

commented Oct 2, 2018

It would be good if we could generate XML in the same way that works for HTML. My current use case is for generating a sitemap.xml, which was talked about a bit in #9. I want to export the site but have some urls which aren't directly linked to (or perhaps non-deterministically) so it's nice to know they can be spidered.

Currently when I add a .xml to src/routes/ I get this and error trying to start the server.

✗ server
Unexpected token
@Rich-Harris

This comment has been minimized.

Copy link
Member

commented Oct 2, 2018

Here's how I'm generating an RSS feed for Svelte Hacker News — https://github.com/sveltejs/sapper-hacker-news/blob/master/src/routes/%5Blist%5D/rss.js. If I wanted the .xml file extension I'd just call it rss.xml.js. Not exactly what you're after, but it's a solution.

I guess you could try doing sitemap.xml.html to use component syntax? Not sure if that'd work or not

@aubergene

This comment has been minimized.

Copy link
Contributor Author

commented Oct 2, 2018

Ah cool, this is a good solution, thanks!

I had a play around with sitemap.xml.html and it looks promising, I think it just needs a way to change the template.html and ideally _layout.html, it didn't look like they configurable at the moment.

@Rich-Harris

This comment has been minimized.

Copy link
Member

commented Oct 2, 2018

Good point. I don't think that's likely to change. But you could maybe do it this way:

// src/routes/sitemap.xml.js
import Sitemap from './_Sitemap.html';

export function get(req, res) {
  const sitemap = Sitemap.render(...);
  res.writeHead(200, {
    'Content-Type': 'application/rss+xml'
  });
  res.end(sitemap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.