Create google sitemap in your sapper/svelte project

I have finished almost with my personal blog site today. My last step is to create on sitemap file in website.

According to google, sitemap files can be in TXT format too. For more details visit the google site.

I decided to create on .txt with I have followed the following steps.

<script context="module">
export async function preload({ params, query }) {
const respost = await this.fetch(``, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
const postparsed = await respost.json();
return { links: postparsed};

export let links = [];
const fs = require('fs');
fs.writeFile('static/map.txt', '', function(){})
links.forEach(link => {
var url = ''+link.slug+'\n';
fs.appendFile('static/map.txt', url, function (err) {
if (err) throw err;

I just read all my posts from the API and written the URL in a plain text file at location static/map.txt. Then submitted my url to the google sitemap submission page.


  • Roopz © 2020