Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

handlebars-helper-sitemap

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handlebars-helper-sitemap

Handlebars helpers and templates for generating a sitemap.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

handlebars-helper-sitemap NPM version NPM monthly downloads NPM total downloads Linux Build Status

Handlebars helpers and templates for generating a sitemap.

Install

Install with npm:

$ npm install --save handlebars-helper-sitemap

Quickstart

Register the sitemap helpers and templates with assemble:

var assemble = require('assemble');
var sitemap = require('handlebars-helper-sitemap');

// sitemap helpers and templates
var templates = sitemap.templates;
var helpers = sitemap.helpers;

// register the helpers
app.helpers(helpers);

// create a "view" for the sitemap and tell 
// assemble the engine to use for rendering
var view = app.view('sitemap.xml', {
  contents: template, 
  engine: 'hbs'
});

// load "pages" for site
app.task('default', function() {
  app.pages('templates/*.hbs');
  return app.toStream('pages')
    .pipe(view.toStream()) //<= add sitemap
    .pipe(app.renderFile())
    .pipe(app.dest('site'));
});

Or you can do it as separate tasks if you want

// load "pages" for site
app.task('pages', function() {
  app.pages('templates/*.hbs');
  return app.toStream('pages')
    .pipe(app.renderFile())
    .pipe(app.dest('site'));
});

// generate sitemap
app.task('sitemap', function() {
  return view.toStream()
    .pipe(app.renderFile('hbs')) // you can define engine here
    .pipe(app.dest('site'));
});

app.task('default', ['pages', 'sitemap']);

Defining sitemap data

Global data

The only required value is sitemap.url, which will be prefixed to all of the relative paths for each <loc> tag:

app.data('sitemap.url', 'https://breakdance.io');

Item data

An item is represents a single URL in the sitemap (since you might be generating a sitemap that includes multiple collections, like "pages" and "posts", item is used to avoid ambiguity.

You can set item.data using yaml-front matter, or using any gulp or assemble plugin that does this, or an assemble middleware. Example:

app.onLoad(/\.md$/, function(file, next) {
  file.data.sitemap = file.data.sitemap || {};
  if (file.stem === 'index') {
    file.data.sitemap.priority = '1.0';
  } else {
    file.data.sitemap.priority = '0.5';
  }
  next();
});

Sitemap tags

The following tags are generated using the global sitemap data and/or the item.data for each file in the sitemap:

| Tag | Description | | <lastmod> | the date of last modification of the file. See the FAQ section for more details about <lastmod> | | <loc> | URL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2,048 characters. | | <changefreq> | How frequently the page is likely to change. | | <priority> | The priority of this URL relative to other URLs on your site. |

See the sitemaps protocol documentation for more information about these tags.

Example sitemap

Generates a sitemap like the following:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://breakdance.io/aaa.html</loc>
    <lastmod>2017-02-11</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://breakdance.io/bbb.html</loc>
    <lastmod>2017-02-02</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://breakdance.io/ccc.html</loc>
    <lastmod>2017-02-02</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.

This file was generated by verb-generate-readme, v0.6.0, on July 20, 2017.

Keywords

compile

FAQs

Package last updated on 20 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts