Skip to content

Samuel-Moncarey/custom_sitemap

 
 

Repository files navigation

simplemap

simplemap is a simple sitemap generator for Drupal 7.

Features

simplemap has the following features:

  • Generate sitemaps conforming to the sitemaps.org specification.
  • Generate image sitemaps, conforming to the Google specification.
  • Support for creating sitemaps for single or multiple content types.
  • Support for internationalized sitemaps.
  • Automatically update the created sitemaps during Cron execution.
  • Drush task for manually launching the sitemap creation.
  • Support for extension with custom sitemap generators.

Installation

Clone this repository into the modules directory of your Drupal site. The preferred path for contributed modules is into sites/all/modules/contrib.

When simplemap is copied into the modules directory enable it with the following command:

drush en simplemap

When simplemap is enabled you should rebuild the registry cache so Drupal can detect the new hooks that it provides. The simplest way to rebuild the cache is with the command:

drush cc all

Configuration

Adding Content to Sitemaps

In admin/settings/simplemap/inclusions, simplemap provides a configuration panel in which you can create sitemaps and attach content types to them.

You can select one or more content types and the specify the name of the sitemap that will contain them (the .xml extension will be added automatically).
If you select the Internationalize option, a sitemap will be created for each language available in your site.

Excluding Content from Sitemaps

In admin/settings/simplemap/exclusions, simplemap provides a configuration panel in which you can specify which nodes should not appear in the generated sitemaps.

Extensibility

As stated in the features, simplemap's functionality can be extended with custom sitemap generators.

  1. Create your own generator class. It must extend the SimplemapGeneratorBase abstract class provided by simplemap and implement the generate() method, which will be automatically called during simplemap execution.

    <?php
    module_load_include('php', 'simplemap', 'classes/generators/SimplemapGeneratorBase');
    
    /**
    * Example custom sitemap generator. It is MANDATORY that you extend the
    * SimplemapGeneratorBase abstract class, which provides the following variables:
    *  - $path: the path where simplemap stores the generated sitemaps.  Any
    *    sitemap stored outside of this path will not be automatically detected.
    *  - $writer: XMLWriter instance that you can use to write the sitemap content.
    */
    class MyCustomGenerator extends SimplemapGeneratorBase {
    
      private $repo_url;
    
      public function __construct($path) {
        parent::__construct($path);
        $this->repo_url = 'https://github.com/simplelogica/simplemap';
      }
    
      public function generate() {
        watchdog('mymodule', "I'm being called by Simplemap!");
        $this->writer->openURI("{$path}/my_custom_sitemap.xml");
        $this->writer->startDocument('1.0', 'UTF-8');
        $this->writer->startElement('urlset');
        $this->writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
    
          $this->writer->startElement('url');
          $this->writer->writeElement('loc', $repo_url);
          $this->writer->endElement();
    
        $this->writer->endElement();
        $this->writer->endDocument();
        $this->writer->flush();
      }
    }
  2. Implement hook_register_simplemap_generator from your module. All you have to do is return the name of your custom generator class.

    <?php
    /**
     * Implements hook_register_simplemap_generator().
     */
    function mymodule_register_simplemap_generator() {
      // Remember to include the file wich contains your generated class.
      return 'MyCustomGenerator';
    }

About

Custom sitemap generator for Drupal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%