Coder Social home page Coder Social logo

meteor-sitemap-creator's Introduction

meteor-sitemap-creator

Package for generating server side XML sitemaps.

How to use (with iron:router)

  • Define a sitemap route for iron:router.
	// Sitemap route
	this.route('sitemap', {
		path: 'sitemap.xml',
		// HAS TO BE on the server.
		where: 'server'
	});
  • Sweet, now add an action method for the sitemap route. Create a collection of the data you want for the sitemap, and pass the collection to the SitemapCreator.createXMLSitemap( collection, rootUrl, mapMethodCallback ) method along with your rootUrl. The collection you pass must only contain items which has the keys loc (required), lastmod, priority and changefreq. If the collection items contain more keys (or not the required loc) an error will be thrown.
	action: function () {
			
		// Let's get some stuff from MongoDB!
		// (This can just be an array with whatever though.)
		// (And don't forget the .fetch() if you're using MongoDB!)
		var collectionOfPages = YourWebsitesPages.find(
			{ status: "live" },
			{ fields: { url: 1, updatedDate: 1, sitemapPrio: 1 } }
			).fetch();

		var collectionForXMLcreation = _( collectionOfPages ).map( function ( page ) {
			// This map method will prepare a new array of items for the actual XML creation.
			// You'll have to provide a "loc" value, the rest of the keys them are optional.
			// You can NOT provide any other keys, only these four!
			return {
				loc: page.url,
				lastmod: new Date( page.updatedDate ),
				priority: page.sitemapPrio,
				changefreq: 'monthly'
			};
		});
      
		// Pass the collection aloing with a rootUrl string and a map method callback.
		// The xmlSitemap var will contain the XML for the sitemap!
		var xmlSitemap = SitemapCreator.createXMLSitemap( collectionForXMLcreation, 'http://www.your-root-url.com' );
		
		// Write the response from the server!
		this.response.writeHead(200, {'Content-Type': 'text/xml'});
		this.response.end( xmlSitemap );
			
	}
  • Now navigate to your site and go to /sitemap.xml (or whatever route you chose for your sitemap) and enjoy your sweet sweet sitemap.

Stuff to think about

  • The sitemap will be ordered by 1. priorty 2. lastmod.
  • Every item in the sitemap must have a unique loc value. Failing this will throw an error.

Bugs etc.

This was created in very little time, and bugs are probably bound to be discover. Please let me konw in the issues if that happens! :)

meteor-sitemap-creator's People

Contributors

krstffr avatar

Stargazers

 avatar

Watchers

 avatar  avatar

meteor-sitemap-creator's Issues

Error after installing package

Am having errors after installing package,

ReferenceError: sitemaps is not defined
W20160129-05:59:34.187(3)? (STDERR)     at /home/okech/projects/web/realestate1/.meteor/local/build/programs/server/app/server/sitemaps.js:9:1
W20160129-05:59:34.187(3)? (STDERR)     at /home/okech/projects/web/realestate1/.meteor/local/build/programs/server/app/server/sitemaps.js:35:4
W20160129-05:59:34.187(3)? (STDERR)     at /home/okech/projects/web/realestate1/.meteor/local/build/programs/server/boot.js:242:10
W20160129-05:59:34.188(3)? (STDERR)     at Array.forEach (native)
W20160129-05:59:34.188(3)? (STDERR)     at Function._.each._.forEach (/home/okech/.meteor/packages/meteor-tool/.1.1.10.11l26ze++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20160129-05:59:34.188(3)? (STDERR)     at /home/okech/projects/web/realestate1/.meteor/local/build/programs/server/boot.js:137:5
=> Exited with code: 8

now my project is messed up tried removing the package but still encountering the same error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.