Skip to content

roljohntorralba/gatsby-plugin-advanced-sitemap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gatsby-plugin-advanced-sitemap-mod

This is a fork of gatsby-plugin-advanced-sitemap, with a few new options added:

  • hideAttribution boolean = optional: hide "Ghost" attribution line from XSL stylesheet.
  • localImageHostname string = optional: Hostname prefix to add to image URLs that don't contain leading hostnames (e.g. missing "http://hostname.com").
  • resultKey string = optional: access for query data not at root, but instead under a container key (i.e. 'postgres').

The default Gatsby sitemap plugin generates a simple blob of raw XML for all your pages. This advanced sitemap plugin adds more power and configuration, generating a single or multiple sitemaps with full XSL templates to make them neatly organised and human + machine readable, as well linking image resources to encourage media indexing.

Demo: https://gatsby.ghost.org/sitemap.xml

 

example

NOTE: This plugin only generates output in production mode! To test, run: gatsby build && gatsby serve

 

Install

npm install --save gatsby-plugin-advanced-sitemap

How to Use

By default this plugin will generate a single sitemap of all pages on your site, without any configuration needed.

// gatsby-config.js

siteMetadata: {
    siteUrl: `https://www.example.com`,
},
plugins: [
    `gatsby-plugin-advanced-sitemap`
]

 

Options

If you want to generate advanced, individually organised sitemaps based on your data, you can do so by passing in a query and config. The example below uses Ghost, but this should work with any data source - including Pages, Markdown, Contentful, etc.

Example:

// gatsby-config.js

plugins: [
    {
        resolve: `gatsby-plugin-advanced-sitemap`,
        options: {
             // 1 query for each data type
            query: `
            {
                allGhostPost {
                    edges {
                        node {
                            id
                            slug
                            updated_at
                            feature_image
                        }
                    }
                }
                allGhostPage {
                    edges {
                        node {
                            id
                            slug
                            updated_at
                            feature_image
                        }
                    }
                }
                allGhostTag {
                    edges {
                        node {
                            id
                            slug
                            feature_image
                        }
                    }
                }
                allGhostAuthor {
                    edges {
                        node {
                            id
                            slug
                            profile_image
                        }
                    }
                }
            }`,
            mapping: {
                // Each data type can be mapped to a predefined sitemap
                // Routes can be grouped in one of: posts, tags, authors, pages, or a custom name
                // The default sitemap - if none is passed - will be pages
                allGhostPost: {
                    sitemap: `posts`,
                },
                allGhostTag: {
                    sitemap: `tags`,
                },
                allGhostAuthor: {
                    sitemap: `authors`,
                },
                allGhostPage: {
                    sitemap: `pages`,
                },
            },
            exclude: [
                `/dev-404-page`,
                `/404`,
                `/404.html`,
                `/offline-plugin-app-shell-fallback`,
                `/my-excluded-page`,
                /(\/)?hash-\S*/, // you can also pass valid RegExp to exclude internal tags for example
            ],
            createLinkInHead: true, // optional: create a link in the `<head>` of your site
            addUncaughtPages: true, // optional: will fill up pages that are not caught by queries and mapping and list them under `sitemap-pages.xml`
            hideAttribution: false, // optional: hide "Ghost" attribution line from XSL stylesheet
            localImageHostname: null, // optional: Hostname prefix to add to local internal image urls
            resultKey: null, // optional: access for query data not at root, but instead under a container key (i.e. 'postgres')
            additionalSitemaps: [ // optional: add additional sitemaps, which are e. g. generated somewhere else, but need to be indexed for this domain
                {
                    name: `my-other-posts`,
                    url: `/blog/sitemap-posts.xml`,
                },
                {
                    url: `https://example.com/sitemap.xml`,
                },
            ],
        }
    }
]

Example output of ☝️ this exact config 👉 https://gatsby.ghost.org/sitemap.xml

 

Copyright & License

Copyright (c) 2013-2020 Ghost Foundation - Released under the MIT license.

About

Advanced XML Sitemaps for Gatsby.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 78.3%
  • XSLT 21.7%