Git Product home page Git Product logo

middleman-search_engine_sitemap's Introduction

Middleman Search Engine Sitemap

Build Status Code Climate Dependency Status Gem Version

Sitemaps are an open standard to tell search engines (such as Google) about each page on your site, how often they're updated, and how important each page is, relative to other pages on your site.

This project aims to simplify serving the sitemap XML file from your Middleman site, so that you can better instruct search engines on how to index your pages.

For more information on the standard itself, please visit http://www.sitemaps.org/.

Installation

Add this line to your Middleman 4.x site's Gemfile:

gem 'middleman-search_engine_sitemap'

If you're using Middleman 3.x, use version 1.3:

gem 'middleman-search_engine_sitemap', '~> 1.3.0'

And then execute:

bundle

Usage

Place the following inside your config.rb:

set :url_root, 'http://example.com'

activate :search_engine_sitemap

The sitemap will become available at http://localhost:4567/sitemap.xml.

Priority and change frequency

Aside from helping identify which pages for search engines should crawl, you can also indicate which pages are more important than others, and how frequently they change.

By default, all pages have a priority of 0.5 (out of 1.0) and a monthly change frequency.

You can change these values by passing in options to the activate directive:

activate :search_engine_sitemap, default_priority: 0.5,
                                 default_change_frequency: "monthly"

You can override the priority or change frequency for a particular page by using frontmatter:

---
title: Blog
priority: 1.0
change_frequency: daily
---

Welcome to my blog! This page is particularly important, and changes often.

Priority

A number between 0.0 and 1.0, representing how important the page is, relative to other pages on your site.

The default value is 0.5.

From sitemaps.org:

Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites–it only lets the search engines know which pages you deem most important for the crawlers.

Please note that the priority you assign to a page is not likely to influence the position of your URLs in a search engine's result pages. Search engines may use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your most important pages are present in a search index.

Also, please note that assigning a high priority to all of the URLs on your site is not likely to help you. Since the priority is relative, it is only used to select between URLs on your site.

Change Frequency

Possible values are: always, hourly, daily, weekly, monthly, yearly, never.

The default value is monthly.

Excluding pages

You can add a hide_from_sitemap attribute to your page's frontmatter to omit it from the sitemap:

---
title: My hidden page
hide_from_sitemap: true
---

Shh. Don't tell anyone I'm here.

If you would like to use a different frontmatter attribute from hide_from_sitemap, you can specify one in the extension options:

activate :search_engine_sitemap, exclude_attr: 'hidden'

This would allow you to use hidden: true in place of hide_from_sitemap: true.

You can also use exclude_if to exclude pages based on more complex requirements. For example:

# Exclude all pages which have a date that's after today
activate :search_engine_sitemap, exclude_if: ->(resource) {
  resource.data.date && resource.data.date > Date.today
}

The value passed into exclude_if can any object that responds to call.

Customising the URL

Sometimes, you might want to alter the URLs that search engines will crawl:

activate :search_engine_sitemap, process_url: -> (url) { url.chomp('/') }

The example above would remove a trailing slash from a URL.

The value passed into process_url can any object that responds to call.

Contributing

  1. Fork it ( http://github.com/Aupajo/middleman-search_engine_sitemap/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

middleman-search_engine_sitemap's People

Contributors

vortizhe avatar aupajo avatar createdbypete avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.