kubernetes-handbook/gitbook-plugin-sitemap/node_modules/sitemap
Jimmy Song 1a5e3f08c0
update plugin
2022-02-22 15:54:51 +08:00
..
env update plugin 2022-02-22 15:54:51 +08:00
lib update plugin 2022-02-22 15:54:51 +08:00
.npmignore update plugin 2022-02-22 15:54:51 +08:00
LICENSE update plugin 2022-02-22 15:54:51 +08:00
README.md update plugin 2022-02-22 15:54:51 +08:00
bower.json update plugin 2022-02-22 15:54:51 +08:00
index.js update plugin 2022-02-22 15:54:51 +08:00
package.json update plugin 2022-02-22 15:54:51 +08:00

README.md

sitemap.js

sitemap.js is a high-level sitemap-generating framework that makes creating sitemap XML files easy.

Table of Contents

Created by gh-md-toc

Installation

It's recommended to install via npm:

npm install --save sitemap

Usage

The main functions you want to use in the sitemap module are

var sm = require('sitemap')
// Creates a sitemap object given the input configuration with URLs
var sitemap = sm.createSitemap({ options });
// Generates XML with a callback function
sitemap.toXML( function(xml){ console.log(xml) });
// Gives you a string containing the XML data
var xml = sitemap.toString();

###Example of using sitemap.js with express:

var express = require('express')
  , sm = require('sitemap');

var app = express()
  , sitemap = sm.createSitemap ({
      hostname: 'http://example.com',
      cacheTime: 600000,        // 600 sec - cache purge period
      urls: [
        { url: '/page-1/',  changefreq: 'daily', priority: 0.3 },
        { url: '/page-2/',  changefreq: 'monthly',  priority: 0.7 },
        { url: '/page-3/'},    // changefreq: 'weekly',  priority: 0.5
        { url: '/page-4/',   img: "http://urlTest.com" }
      ]
    });

app.get('/sitemap.xml', function(req, res) {
  sitemap.toXML( function (xml) {
      res.header('Content-Type', 'application/xml');
      res.send( xml );
  });
});

app.listen(3000);

###Example of synchronous sitemap.js usage:

var express = require('express')
  , sm = require('sitemap');

var app = express()
  , sitemap = sm.createSitemap ({
      hostname: 'http://example.com',
      cacheTime: 600000,  // 600 sec cache period
      urls: [
        { url: '/page-1/',  changefreq: 'daily', priority: 0.3 },
        { url: '/page-2/',  changefreq: 'monthly',  priority: 0.7 },
        { url: '/page-3/' } // changefreq: 'weekly',  priority: 0.5
      ]
    });

app.get('/sitemap.xml', function(req, res) {
  res.header('Content-Type', 'application/xml');
  res.send( sitemap.toString() );
});

app.listen(3000);

###Example of dynamic page manipulations into sitemap:

var sitemap = sm.createSitemap ({
      hostname: 'http://example.com',
      cacheTime: 600000
    });
sitemap.add({url: '/page-1/'});
sitemap.add({url: '/page-2/', changefreq: 'monthly', priority: 0.7});
sitemap.del({url: '/page-2/'});
sitemap.del('/page-1/');

###Example of pre-generating sitemap based on existing static files:

var sm = require('sitemap')
    , fs = require('fs');

var sitemap = sm.createSitemap({
    hostname: 'http://www.mywebsite.com',
    cacheTime: 600000,  //600 sec (10 min) cache purge period
    urls: [
        { url: '/' , changefreq: 'weekly', priority: 0.8, lastmodrealtime: true, lastmodfile: 'app/assets/index.html' },
        { url: '/page1', changefreq: 'weekly', priority: 0.8, lastmodrealtime: true, lastmodfile: 'app/assets/page1.html' },
        { url: '/page2'    , changefreq: 'weekly', priority: 0.8, lastmodrealtime: true, lastmodfile: 'app/templates/page2.hbs' } /* useful to monitor template content files instead of generated static files */
    ]
});

fs.writeFileSync("app/assets/sitemap.xml", sitemap.toString());

###Example of indicating alternate language pages:

Description in the google's Search Console Help.

var sm = sm.createSitemap({
      urls: [{
        url: 'http://test.com/page-1/',
        changefreq: 'weekly',
        priority: 0.3,
        links: [
          { lang: 'en', url: 'http://test.com/page-1/', },
          { lang: 'ja', url: 'http://test.com/page-1/ja/', },
        ]
      },]
    });

License

See LICENSE file.