All Projects → lgraubner → Sitemap Generator

lgraubner / Sitemap Generator

Licence: mit
Easily create XML sitemaps for your website.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sitemap Generator

Sitemap Generator Cli
Creates an XML-Sitemap by crawling a given site.
Stars: ✭ 214 (-21.61%)
Mutual labels:  google, sitemap, crawler, seo
Sitemap Generator Crawler
Script that generates a sitemap by crawling a given URL
Stars: ✭ 169 (-38.1%)
Mutual labels:  sitemap, crawler, seo
Laravel Sitemap
Create and generate sitemaps with ease
Stars: ✭ 1,325 (+385.35%)
Mutual labels:  google, sitemap, seo
Google Group Crawler
Get (almost) original messages from google group archives. Your data is yours.
Stars: ✭ 190 (-30.4%)
Mutual labels:  google, crawler
Laravel Robots Middleware
Enable or disable the indexing of your app
Stars: ✭ 259 (-5.13%)
Mutual labels:  google, seo
Search Engine Optimization
🔍 A helpful checklist/collection of Search Engine Optimization (SEO) tips and techniques.
Stars: ✭ 1,798 (+558.61%)
Mutual labels:  google, seo
Magic google
Google search results crawler, get google search results that you need
Stars: ✭ 247 (-9.52%)
Mutual labels:  google, crawler
vuepress-plugin-sitemap
Sitemap generator plugin for vuepress.
Stars: ✭ 92 (-66.3%)
Mutual labels:  sitemap, seo
classicpress-seo
Classic SEO is the first SEO plugin built specifically to work with ClassicPress. A fork of Rank Math, the plugin contains many essential SEO tools to help optimize your website.
Stars: ✭ 18 (-93.41%)
Mutual labels:  sitemap, seo
sitemap-checker
a tool for validate xml sitemap and sitemap index files for broken links
Stars: ✭ 21 (-92.31%)
Mutual labels:  sitemap, seo
siteshooter
📷 Automate full website screenshots and PDF generation with multiple viewport support.
Stars: ✭ 63 (-76.92%)
Mutual labels:  sitemap, seo
sitemap
A simple sitemap generator for Laravel Framework.
Stars: ✭ 32 (-88.28%)
Mutual labels:  sitemap, seo
Curatedseotools
Best SEO Tools Stash
Stars: ✭ 128 (-53.11%)
Mutual labels:  google, seo
Fawkes
Fawkes is a tool to search for targets vulnerable to SQL Injection. Performs the search using Google search engine.
Stars: ✭ 108 (-60.44%)
Mutual labels:  google, crawler
Youtube Projects
This repository contains all the code I use in my YouTube tutorials.
Stars: ✭ 144 (-47.25%)
Mutual labels:  google, crawler
D4n155
OWASP D4N155 - Intelligent and dynamic wordlist using OSINT
Stars: ✭ 105 (-61.54%)
Mutual labels:  google, crawler
strapi-plugin-sitemap
🔌 Generate a highly customizable sitemap XML in Strapi CMS
Stars: ✭ 136 (-50.18%)
Mutual labels:  sitemap, seo
Serp
Google Search SERP Scraper
Stars: ✭ 40 (-85.35%)
Mutual labels:  google, seo
Is Google
Verify that a request is from Google crawlers using Google's DNS verification steps
Stars: ✭ 82 (-69.96%)
Mutual labels:  google, crawler
Silverstripe-SEO
A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content
Stars: ✭ 41 (-84.98%)
Mutual labels:  sitemap, seo

Sitemap Generator

Travis David npm

Easily create XML sitemaps for your website.

Generates a sitemap by crawling your site. Uses streams to efficiently write the sitemap to your drive and runs asynchronously to avoid blocking the thread. Is cappable of creating multiple sitemaps if threshold is reached. Respects robots.txt and meta tags.

This package is not meant to be used in a production code base directly, but rather on the deployed product. This means you develop your app/website as usual, deploy it and create the sitemap with this tool afterwards. The simplest way is to use the CLI (this is a different package!) to create the sitemap on the command line. If you have a more advanced usecase or want to adjust the crawler behavior you should use the programmtic version (this package). Create the crawler as needed and simply run it via node mycrawler.js.

Table of contents

Install

This module is available on npm.

$ npm install -S sitemap-generator

This module is running only with Node.js and is not meant to be used in the browser.

Usage

const SitemapGenerator = require('sitemap-generator');

// create generator
const generator = SitemapGenerator('http://example.com', {
  stripQuerystring: false
});

// register event listeners
generator.on('done', () => {
  // sitemaps created
});

// start the crawler
generator.start();

The crawler will fetch all folder URL pages and file types parsed by Google. If present the robots.txt will be taken into account and possible rules are applied for each URL to consider if it should be added to the sitemap. Also the crawler will not fetch URL's from a page if the robots meta tag with the value nofollow is present and ignore them completely if noindex rule is present. The crawler is able to apply the base value to found links.

API

The generator offers straightforward methods to start and stop it. You can also add URL's manually.

start()

Starts crawler asynchronously and writes sitemap to disk.

stop()

Stops the running crawler and halts the sitemap generation.

getCrawler()

Returns the crawler instance. For more information about the crawler check the simplecrawler docs.

This can be useful to ignore certain sites and don't add them to the sitemap.

const crawler = generator.getCrawler();
crawler.addFetchCondition((queueItem, referrerQueueItem, callback) => {
  callback(null, !queueItem.path.match(/myregex/));
});

getSitemap()

Returns the sitemap instance (SitemapRotator).

This can be useful to add static URLs to the sitemap:

const crawler = generator.getCrawler()
const sitemap = generator.getSitemap()

// Add static URL on crawl init.
crawler.on('crawlstart', () => {
  sitemap.addURL('/my/static/url')
})

queueURL(url)

Add a URL to crawler's queue. Useful to help crawler fetch pages it can't find itself.

Options

There are a couple of options to adjust the sitemap output. In addition to the options beneath the options of the used crawler can be changed. For a complete list please check it's official documentation.

var generator = SitemapGenerator('http://example.com', {
  maxDepth: 0,
  filepath: './sitemap.xml',
  maxEntriesPerFile: 50000,
  stripQuerystring: true
});

changeFreq

Type: string
Default: undefined

If defined, adds a <changefreq> line to each URL in the sitemap. Possible values are always, hourly, daily, weekly, monthly, yearly, never. All other values are ignored.

filepath

Type: string
Default: ./sitemap.xml

Filepath for the new sitemap. If multiple sitemaps are created "part_$index" is appended to each filename. If you don't want to write a file at all you can pass null as filepath.

httpAgent

Type: HTTPAgent
Default: http.globalAgent

Controls what HTTP agent to use. This is useful if you want configure HTTP connection through a HTTP/HTTPS proxy (see http-proxy-agent).

httpsAgent

Type: HTTPAgent
Default: https.globalAgent

Controls what HTTPS agent to use. This is useful if you want configure HTTPS connection through a HTTP/HTTPS proxy (see https-proxy-agent).

ignore(url)

Apply a test condition to a URL before it's added to the sitemap.

Type: function
Default: null

Example:

const generator = SitemapGenerator(url, {
  ignore: url => {
    // Prevent URLs from being added that contain `<pattern>`.
    return /<pattern>/g.test(url)
  }
})

ignoreAMP

Type: boolean
Default: true

Indicates whether Google AMP pages should be ignored and not be added to the sitemap.

lastMod

Type: boolean
Default: false

Whether to add a <lastmod> line to each URL in the sitemap. If present the responses Last-Modified header will be used. Otherwise todays date is added.

maxEntriesPerFile

Type: number
Default: 50000

Google limits the maximum number of URLs in one sitemap to 50000. If this limit is reached the sitemap-generator creates another sitemap. A sitemap index file will be created as well.

priorityMap

Type: array
Default: []

If provided, adds a <priority> line to each URL in the sitemap. Each value in priorityMap array corresponds with the depth of the URL being added. For example, the priority value given to a URL equals priorityMap[depth - 1]. If a URL's depth is greater than the length of the priorityMap array, the last value in the array will be used. Valid values are between 1.0 and 0.0.

Example:

[1.0, 0.8, 0.6, 0.4, 0.2, 0]

userAgent

Type: string
Default: Node/SitemapGenerator

Change the default crawler user agent.

Events

The Sitemap Generator emits several events which can be listened to.

add

Triggered when the crawler successfully added a resource to the sitemap. Passes the url as argument.

generator.on('add', (url) => {
  // log url
});

done

Triggered when the crawler finished and the sitemap is created.

generator.on('done', () => {
  // sitemaps created
});

error

Thrown if there was an error while fetching an URL. Passes an object with the http status code, a message and the url as argument.

generator.on('error', (error) => {
  console.log(error);
  // => { code: 404, message: 'Not found.', url: 'http://example.com/foo' }
});

ignore

If an URL matches a disallow rule in the robots.txt file or meta robots noindex is present this event is triggered. The URL will not be added to the sitemap. Passes the ignored url as argument.

generator.on('ignore', (url) => {
  // log ignored url
});

FAQ

Does this work with React, Angular, ...

This package don't care what frameworks and technologies you are using under the hood. The only requirement is, that your URL's return valid HTML. Therefore SSR (server side rendering) is required for single page apps as no JavaScript is executed.

Where to put this code

This is basically up to you. You can execute this code manually and upload your sitemap by hand, or you can put this on your server and run this periodically to keep your sitemap up to date.

Should I use this package or the CLI

The CLI should suffice most of the common use cases. It has several options to tweak in case you want it to behave differently. If your use case is more advanced and you need fine control about what the crawler should fetch, you should use this package and the programmatic API.

License

MIT © Lars Graubner

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].