2017-25 © Pedro Peláez
 

library monal-sitemap

Sitemap generator for Monal CMS.

image

ash/monal-sitemap

Sitemap generator for Monal CMS.

  • Wednesday, July 9, 2014
  • by Ash
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Monal Sitemap

Sitemap generator for Monal CMS. Allows the registering of entities on a package by package basis., (*1)

By default Monal Sitemap places sitemaps at sitemap and sitemap.xml. This name can be customised via the config['filename'] option., (*2)

Installation

  1. Add ash\monal-sitemap as a Composer dependency and install
  2. Add 'Ash\MonalSitemap\MonalSitemapServiceProvider' to app providers
  3. Add 'Sitemap' => 'Ash\MonalSitemap\Facades\Sitemap' to app aliases

Registering a sitemap section

Monal Sitemap consists of collections of entities. An entity can be either a single entity (a SitemapEntity) or a collection of entities (a SitemapCollection)., (*3)

Entities are registered using the register function., (*4)

Sitemap::register( string $name, Callable $register [, $cache ] )

$name

The name of the collection / entity. Must be unique., (*5)

$register

A function that returns either an instance of SitemapCollection or SitemapEntity., (*6)

$cache

Override the default cache (1440 minutes). Set to either a custom number of minutes, or false to disable caching., (*7)

SitemapEntity and SitemapCollection

SitemapEntity and SitemapCollection are identical in all regards other than SitemapCollections ability to contain a collection of entities., (*8)

$entity/$collection->uri - required

Full URI of the entity (excluding domain)., (*9)

$entity/$collection->name - required

$entity/$collection->lastmod

$entity/$collection->changefreq

$entity/$collection->priority

$collection->add($collection/$entity)

Add a collection or entity to the collection. Can be chained or given an array, for example:, (*10)

$collection
    ->add($subCollection)
    ->add($subCollection2);

$collection->add([
    $subCollection,
    $subCollection2
]);

Example

// Register a collection named 'products'

Sitemap::register('products', function($uri) {

    // The second param of the register function is a callback
// that should return a collection or an entity

    // Create a new collection
    $collection = App::make('SitemapCollection');

    // Set the collection URI
    // $uri passed to this callback is the same as the collection name (products)
    $collection->uri = $uri;

    $collection->name = 'Products';

    // Gather data for a resource   
    foreach(Product::all() as $product) {

        // Create a new single entity
        $entity = App::make('SitemapEntity');

        // Set entity URI
        $entity->uri = 'products/' . $product->uri;

        $entity->name = $product->name;

        // Set entity lastmod
        // The default Laravel updated_at timestamp works here
        $entity->lastmod = $product->updated_at;

        // Add the single entity to the collection
        $collection->add($entity);

    }

    return $collection;

});

Templating

The sitemap uses a view called sitemap.blade.php that you can publish to your local view directory in order to customise. The sitemap object is passed to the view as $sitemap., (*11)

You can either iterate through the collections and entities manually, or use the $sitemap->html() function to output a <ul> containing the sitemap., (*12)

Iterating through the sitemap to create a custom output is very simple, see the use of Blade's @each function in the default view., (*13)

Todo

  • Should / could this be a generic Laravel tool, rather than being for Monal?
  • Add entity validation - $entity->valid() is checked upon adding, currently always returns true
  • Unit tests
  • Add default cache duration as config item
  • Implement gzipping of XML version

Releases

0.1.1 - 09/07/14

  • Fix XML output

0.1.0 - 02/07/14

  • Improved HTML templating (now uses a Blade view that can be published to the local views dir)

0.0.1 - 01/07/14

The Versions

09/07 2014

dev-master

9999999-dev

Sitemap generator for Monal CMS.

  Sources   Download

MIT

The Requires

 

by Avatar Ash

09/07 2014

0.1.1

0.1.1.0

Sitemap generator for Monal CMS.

  Sources   Download

MIT

The Requires

 

by Avatar Ash

02/07 2014

0.1.0

0.1.0.0

Sitemap generator for Monal CMS.

  Sources   Download

MIT

The Requires

 

by Avatar Ash

30/06 2014

0.0.1

0.0.1.0

  Sources   Download

The Requires

 

by Arran Jacques