How to use sitemap - 10 common examples

To help you get started, we’ve selected a few sitemap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phenomic / phenomic / src / loader-sitemap-webpack-plugin / __tests__ / index.js View on Github external
)
      .toBeFalsy()
      if (stats.hasErrors()) {
        console.error(stats.compilation.errors)
      }

      // doesn't give any warning
      expect(
        stats.hasWarnings()
      )
      .toBeFalsy()
      if (stats.hasWarnings()) {
        console.log(stats.compilation.warnings)
      }

      const sitemap = stats.compilation.assets["sitemap.xml"]
      if (!sitemap) {
        console.log(stats.compilation.assets)
      }

      // should create a xml for the sitemap
      expect(
        sitemap && sitemap._value,
      )
      .toBeTruthy()

      // should contain a filtred entry (urlset)
      expect(
        sitemap._value.includes("<urlset xmlns=\"http://www.sitemaps.org"),
      )
      .toBeTruthy()
github numenta / numenta-web / numenta.org / gatsby-node.js View on Github external
)
        }
      }
      const text = [title, content, details.join(' ')].join(' ')
      return {path, text, title}
    })

  // prep sitemap
  const urls = pages
    .filter((page) => page.path)
    .map(({path}) => ({
      url: path,
      changefreq: 'monthly',  // 'daily' @TODO dynamic per file dates, etc
      priority: 0.5,  // @TODO dynamic per url length (shorter=higher)
    }))
  const sitemap = createSitemap({
    hostname: 'http://numenta.org',  // @TODO stringify hostname in config
    urls,
  })

  console.log('postBuild generate search index')
  fs.writeFileSync('public/_searchIndex.json', JSON.stringify(searches))

  console.log('postBuild generate sitemap')
  fs.writeFileSync('public/sitemap.xml', sitemap.toString())

  console.log('postBuild static asset copy')
  return ncp('static/', 'public/', callback)
}
github surmon-china / nodepress / src / modules / sitemap / sitemap.service.ts View on Github external
private reBuild(): Promise<Sitemap> {
    this.sitemap = sitemap.createSitemap({
      cacheTime: 666666,
      urls: [...this.pagesMap],
      // hostname: APP_CONFIG.APP.URL,
    });
    return Promise.all([
      this.addTagsMap(),
      this.addCategoriesMap(),
      this.addArticlesMap(),
    ])
      .then(_ => Promise.resolve(this.sitemap))
      .catch(error => {
        console.warn('生成网站地图前获取数据库发生错误', error);
        return Promise.resolve(this.sitemap);
      });
  }
github HW-Core / universal-pwa / apps / sitemap-gen / express.js View on Github external
}

    Sitemap.sitemaps.map((sitemap, index) => {
        const savePath = fileName.replace('.xml', `-${index}.xml`);

        app.get(basePath + savePath, (req, res) => {
            res.header('Content-Type', 'application/xml');
            res.send(Sitemap.sitemaps[index].toString())
        });

        // push public path for indexing
        sitemapPaths.push(Sitemap.hostname + publicPath + path.basename(savePath));
    });

    // create index string
    const sitemapIndex = sm.buildSitemapIndex({
        urls: sitemapPaths,
        hostname: Sitemap.hostname
    });

    app.get(basePath + fileName, (req, res) => {
        res.header('Content-Type', 'application/xml');
        console.log(sitemapIndex)
        res.send(sitemapIndex)
    });

    return app;
}
github nuxt-community / modules / modules / sitemap / index.js View on Github external
function createSitemap (options, routes, req) {
  const sitemapConfig = {}

  // Set sitemap hostname
  sitemapConfig.hostname = options.hostname ||
    (req && `${isHTTPS(req) ? 'https' : 'http'}://${req.headers.host}`) || `http://${hostname()}`

  // Set urls and ensure they are unique
  sitemapConfig.urls = uniq(routes)

  // Set cacheTime
  sitemapConfig.cacheTime = options.cacheTime || 0

  // Create promisified instance and return
  const sitemap = sm.createSitemap(sitemapConfig)
  sitemap.toXML = pify(sitemap.toXML)

  return sitemap
}
github richardzcode / Dochameleon / lib / core / Assets.js View on Github external
urls.push({url, changefreq: 'weekly', priority: 0.5});
      });

    this.site.blog.metadatas
      .forEach(metadata => {
        const url = metadata.permalink();
        urls.push({url, changefreq: 'weekly', priority: 0.3});
      });

    this.site.docs.metadatas
      .forEach(metadata => {
        const url = metadata.permalink();
        urls.push({url, changefreq: 'weekly', priority: 0.3});
      });

    const sitemap = createSitemap({
      hostname: this.site.rootUrl,
      cacheTime: 600 * 1000, // 600 sec - cache purge period
      urls: urls,
    });

    return new Promise((resolve, reject) => {
      sitemap.toXML((err, xml) => {
        if (err) {
          reject('An error has occured.');
        } else {
          resolve(xml);
        }
      });
    });
  }
github ExtraHop / metalsmith-sitemap / lib / index.js View on Github external
return function(files, metalsmith, done) {
    // Create sitemap object
    var sitemap = sm.createSitemap ({
      hostname: hostname
    });

    // Checks whether files should be processed
    function check(file, frontmatter) {
      // Only process files that match the pattern
      if (!match(file, pattern)[0]) {
        return false;
      }

      // Don't process private files
      if (get(frontmatter, privateProperty)) {
        return false;
      }

      return true;
github prisma-archive / prep / src / index.js View on Github external
timeout: 1000,
        dimensions,
        https: false,
        hostname: 'http://localhost',
        useragent: 'Prep',
        minify: false,
        concurrency: 4,
        additionalSitemapUrls: [],
    }, configuration)

    debug('Config prepared', configuration)

    // render sitemap
    const sitemapUrs = configuration.routes.map(route => ({ url: route }))
        .concat(configuration.additionalSitemapUrls.map(route => ({ url: route })))
    const sm = sitemap.createSitemap({
        hostname: configuration.hostname,
        urls: sitemapUrs,
    })
    mkdirp.sync(targetDir)
    fs.writeFileSync(`${targetDir}/sitemap.xml`, sm.toString());

    debug('Sitemap created')

    // start temporary local webserver
    const app = express()
        .use(serveStatic(buildDir))
        .use(fallback('index.html', { root: buildDir }))
    let server
    if (configuration.https) {
        const credentials = {
            key: fs.readFileSync(`${__dirname}/../ssl/key.pem`),
github kuflash / react-router-sitemap / lib / index.js View on Github external
return this;
		}

		this.sitemaps.map((sitemap, index) => {
			const savePath = dist.replace('.xml', `-${index}.xml`);

			// write sitemap
			fs.writeFileSync(savePath, sitemap.toString());

			// push public path for indexing
			sitemapPaths.push(this.hostname + publicPath + path.basename(savePath));
		});

		// create index string
		const sitemapIndex = sm.buildSitemapIndex({
			urls: sitemapPaths,
			hostname: this.hostname
		});

		// write sitemap index
		fs.writeFileSync(dist, sitemapIndex);

		return this;
	}
github nuxt-community / sitemap-module / lib / builder.js View on Github external
const hostname = getHostname(options.hostname ? options : { ...options, hostname: defaultHostname }, req, base)
    const url = new URL(path, hostname)
    return url.href
  })

  // Set lastmod for each sitemap
  sitemapIndexConfig.lastmod = options.lastmod

  // Set XML namespaces
  sitemapIndexConfig.xmlNs = options.xmlNs

  // Set XSL url
  sitemapIndexConfig.xslUrl = options.xslUrl

  // Create a sitemapindex
  return sm.buildSitemapIndex(sitemapIndexConfig)
}