Yeats
Yeats

Reputation: 2065

How to use the ms-seo package for better SEO in Meteor?

This package, ms-seo is surely great in every way, but sadly its author forgot about newbies like me when he composed the readme. Anyway, as someone who has never contributed anything to any coding community, I'm sure my criticism is worth little, so let's move along.

This particular author provided a blog post along with the package, which was an interesting read, but most of it directly contradicted the readme itself, so I'm lost trying to configure the settings.

The blog post states:

You only need to add the seo data in the following schema:

SeoCollection.insert({
    "route_name" : "home", // the name of the Iron-Router route
    "title" : "Title of your home site",
    "meta" : [
        {"description": "This is the description of the document"},
        // add more meta tags
    ],
    "og" : [
        { "image": "http://your-domain.com/images/image.jpg" },
        // add more open graph tags
    ]
})

My guess here is that the package creates the collection SeoCollection for you, so I only need to fill it with some seed data, one insert for every route of my app. Cool!

Oh, but wait... The readme says something different:

You can set some standard values. This will be set if nothing else is available.

Meteor.startup(function() {
    if (Meteor.isClient) {
        return SEO.config({
            title: 'Manuel Schoebel - MVP Development',
            meta: {
                'description': 'Manuel Schoebel develops Minimal Viable Producs (MVP) for Startups'
            },
            og: {
                'image': 'http://manuel-schoebel.com/images/authors/manuel-schoebel.jpg' 
           }
        });
    }
});

Does he mean that those actual values will be set if I don't provide any configuation, i.e. my site will be called "Manuel Schoebel - MVP Development"? And how does this rhyme with the inserts I had to make? Why is this in the client anyway? And why is there no route name?

The readme goes on and provides some example code for a SeoCollection.update that also seems to do the same thing! So I'm supposed to use update, not insert? And where am I doing this exactly?

But then he talks about using onAfterHooks in Iron Router instead for dynamic data. So should I use that instead of some of all of the above?

I would really love to have some clarification on this. What do I need to do after installing the package?

Upvotes: 4

Views: 619

Answers (1)

halbgut
halbgut

Reputation: 2386

I've never used this package, but this is what I learned from reading the docs/code:

SEO.config

The package has the ability to render different header tags for different routes. So when you insert a new ms-seo configuration you normally pass a route. But you can also configure a default configuration. This is what the whole Meteor.startup SEO.config business is about.

SeoCollection.update

The update call in the docs has the option upsert set to true. This option makes the query update the Database entry if it exists and inserts it if it doesn't. This makes changing things easier and with this it's the ms-seo's state remains unchanged when you do meteor reset. The last time he made an update to the README, he didn't update the blog post.

So I'd advise you to use the documented update statement. Or even, use upsert

SeoCollection.upsert(
  {
    route_name: 'aboutMe'
  },
  {
    $set: {
      route_name: 'aboutMe',
      title: 'About - Manuel Schoebel',
      meta: {
        'description': 'Manuel Schoebel is an experienced web developer and startup founder. He develops but also consults startups about internet topics.'
      },
      og: {
        'title': 'About - Manuel Schoebel',
        'image': 'http://manuel-schoebel.com/images/authors/manuel-schoebel.jpg'
      }
    }
  }
);

The configuration is probably done client-side, to make updating it easier.

SEO.set

Finally the onAfterAction hook is used, so that you don't have to manually specify the current route. You can see that in his code. The SEO.set call basically does the same as the upsert it just checks check for a route specified by iron:router. The SEO.set function doesn't save the settings to the collection. That means, that it has to be executed every time the site loads.

Summary

So if you use iron:router definitely use onAfterAction and SEO.set. Of course you'll still want to use the SEO.config function to set default settings.

Hope that helps.

Upvotes: 6

Related Questions