Anyone using a Meteor/npm package to create its own sitemap?

I’d like to create my own sitemap automatically for Google/Bing crawlers.

Is anyone doing this for their website and using a Meteor/npm package? I’m looking for recommendations.

Thanks in advance!

I created sitemap manually, using webapp to serve site map.

import { WebApp } from 'meteor/webapp';
import jsontoxml from 'jsontoxml';

WebApp.connectHandlers.use('/sitemaps/some-url.xml', (req, res) => {
  res.setHeader('Content-Type', 'text/xml');

  const sitemapData = [
    {
      name: 'urlset',
      attrs: {
        xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9',
      },
      children: [],
    },
  ];

  const pushToSiteMap = ({ loc, lastmod, changefreq = 'weekly' }) => {
    sitemapData[0].children.push({
      name: 'url',
      children: [
        {
          name: 'loc',
          text: SitemapsHelper.escapeURL(loc),
        },
        {
          name: 'lastmod',
          text: moment(lastmod).format(),
        },
        {
          name: 'changefreq',
          text: changefreq,
        },
      ],
    });
  };

  // select items
  const items = MyCollection.find({
    status: 1,
  }, {
    sort: { updatedAt: -1, createdAt: -1 },
    limit: SitemapsHelper.getMaxItemsPerSitemap(),
    fields: {
      'info.url': 1, updatedAt: 1, createdAt: 1,
    },
  });
  items.map((item) => {
    pushToSiteMap({
      loc: Meteor.absoluteUrl(someUrlHere),
      lastmod: item.updatedAt || item.createdAt,
    });
    return item._id;
  });

  res.writeHead(200);
  res.write('<?xml version="1.0" encoding="UTF-8"?>');
  res.end(jsontoxml(sitemapData));
});

Streaming sitemap to S3 using this

2 Likes

Was looking at this packages as well. Seems to be the most popular and is maintained.

The sitemap I want to build includes our Zendesk help articles, so a npm package will do better for our use case.

Thanks for your response though!

1 Like