Learn the API - laravelista/Bard GitHub Wiki
I'd like to show you how to use the API for each class: UrlSet
, Url
, SitemapIndex
and Sitemap
.
UrlSet
This is the class that you would want to use if you were creating a sitemap.
use Laravelista\Bard\UrlSet;
use Sabre\Xml\Writer;
$sitemap = new UrlSet(new Writer)
addUrl($location)
This method adds a Url to the sitemap (UrlSet).
$location
is required and it must be a valid URL.
$sitemap->addUrl('http://acme.me');
This method also return the instance of class Url
. If you want to know what you can do with that instance see Url
.
generate()
You will probably not use this method, but if you insist you will get the sitemap XML output in string type.
return $sitemap->generate();
render()
Now this is a method that you will want to use. It returns output from generate()
method as XML response.
return $sitemap->render();
Url
This class is only used from UrlSet
class as a returned object from addUrl
method. See addUrl
.
setLocation($url)
This will validate given URL and set it as Url location.
You will probably never use this because the location is set when calling the
addUrl
method.
$url
must be a valid URL.
$sitemap->addUrl('http://acme.me')
->setLocation('http://acme.me/different-path');
setLastModification(DateTime $lastModification)
This method sets the last modification date on Url.
$lastModification
must beDateTime
. You can use Carbon to set the date.
$sitemap->addUrl('http://acme.me')
->setLastModification(\Carbon\Carbon::now());
addTranslation($locale, $url)
This adds a translation.
locale
can be any string.$url
must be a valid URL.
$sitemap->addUrl('http://acme.me')
->addTranslation('hr', 'http://acme.me/hr');
setPriority($priority)
This sets priority for Url
.
$priority
must be a number between>=0.0 && <= 1.0
$sitemap->addUrl('http://acme.me')
->setPriority(0.8)
setChangeFrequency($changeFrequency)
This sets the change frequency for Url
.
$changeFrequency
can be:"always", "hourly", "daily", "weekly", "monthly", "yearly", "never"
.
$sitemap->addUrl('http://acme.me')
->setChangeFrequency('hourly');
SitemapIndex
This is the class that you would want to use if you were creating a sitemap index.
use Laravelista\Bard\SitemapIndex;
use Sabre\Xml\Writer;
$sitemapIndex = new SitemapIndex(new Writer);
addSitemap($location)
This will add a sitemap to sitemap index.
$location
is required and it must be a valid URL.
$sitemapIndex->addSitemap('http://acme.me/sitemap-tags.xml');
This method also return the instance of class Sitemap
. If you want to know what you can do with that instance see Sitemap
.
generate()
You will probably not use this method, but if you insist you will get the sitemap index XML output in string type.
return $sitemapIndex->generate();
render()
Now this is a method that you will want to use. It returns output from generate()
method as XML response.
return $sitemapIndex->render();
Sitemap
This class is only used from SitemapIndex
class as a returned object from addSitemap
method. See addSitemap
.
setLocation($url)
This will validate given URL and set it as sitemap location.
You will probably never use this because the location is set when calling the
addSitemap
method.
$location
must be a valid URL.
$sitemapIndex->addSitemap('http://acme.me/sitemap-tags.xml')
->setLocation('http://acme.me/sitemap-tags-index.xml');
setLastModification(DateTime $lastModification)
This method sets the last modification date on sitemap.
$lastModification
must beDateTime
. You can use Carbon to set the date.
$sitemapIndex->addSitemap('http://acme.me/sitemap-tags.xml')
->setLastModification(\Carbon\Carbon::now());