Skip to content

Commit

Permalink
Finalised 2.1 notes and events
Browse files Browse the repository at this point in the history
Signed-off-by: Marty Friedel <[email protected]>
  • Loading branch information
martyf committed May 25, 2022
1 parent f9c9aac commit 23b0666
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ If your site has routes that are not part of Statamic - such as your own custom
you sitemap too.

In your `AppServiceProvider` (or you can create your own SitemapamicServiceProvider if you like too - especially if you
use named routes, keep reading) you can add dynamic routes to Sitemapamic as an array of `SitemapamicUrl` objects:
use named routes, keep reading) you can add dynamic routes to Sitemapamic as a closure that returns an array
of `SitemapamicUrl` objects:

```php
Sitemapamic::addDynamicRoutes(function() {
Expand Down Expand Up @@ -142,7 +143,7 @@ data. How many you add and how you build them is totally up to you.
#### Using named routes in a provider

It would be our recommendation to use Named Routes where you can - so that if you change your route, your sitemap can
pick it automatically.
pick it automatically. It also means you don't have to be hardcoding full URLs in your app.

To do this, you need a little bit of extra work. Firstly, create your own Service Provider, and make sure it is in your
app's config *after* the `RouteServiceProvider`.
Expand Down Expand Up @@ -189,8 +190,7 @@ These fields can alter the behaviour of the sitemap generator per entry or term.
so that you can override and adjust these properties on a case-by-case basis.

This is an opinionated approach for a simple site. If you need greater control of SEO for your site, you may be better
suited to an addon like Statamic's [SEO Pro](https://statamic.com/addons/statamic/seo-pro) (we use this in our larger
sites).
suited to an addon like Statamic's [SEO Pro](https://statamic.com/addons/statamic/seo-pro).

---

Expand All @@ -200,18 +200,21 @@ Your sitemap is cached forever. Well, until you clear it that is.

To clear the cache, you can do one of three things:

- save an entry
- save a taxonomy term
- save (or delete) an Entry
- save (or delete) a Taxonomy or Term
- save (or delete) a Collection
- run a ``please`` command

Saving an entry or term will automatically clear the sitemap cache.
Saving an Entry, Collection, Taxonomy or Term will automatically clear the sitemap cache.

You can force the cache to clear by running:

```
php please sitemapamic:clear
```

This could be a good command to have as part of your deployment script.

---

## Publishing the sitemap view
Expand Down
24 changes: 20 additions & 4 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

use MityDigital\Sitemapamic\Listeners\ClearSitemapamicCache;
use MityDigital\Sitemapamic\Commands\ClearSitemapamicCacheCommand;
use Statamic\Events\CollectionDeleted;
use Statamic\Events\CollectionSaved;
use Statamic\Events\EntryDeleted;
use Statamic\Events\EntrySaved;
use Statamic\Events\TaxonomyDeleted;
use Statamic\Events\TaxonomySaved;
use Statamic\Events\TermDeleted;
use Statamic\Events\TermSaved;
use Statamic\Providers\AddonServiceProvider;
Expand All @@ -23,16 +27,28 @@ class ServiceProvider extends AddonServiceProvider
];

protected $listen = [
EntryDeleted::class => [
CollectionDeleted::class => [
ClearSitemapamicCache::class,
],
EntrySaved::class => [
CollectionSaved::class => [
ClearSitemapamicCache::class,
],
TermDeleted::class => [
EntryDeleted::class => [
ClearSitemapamicCache::class,
],
TermSaved::class => [
EntrySaved::class => [
ClearSitemapamicCache::class,
],
TaxonomyDeleted::class => [
ClearSitemapamicCache::class,
],
TaxonomySaved::class => [
ClearSitemapamicCache::class,
],
TermDeleted::class => [
ClearSitemapamicCache::class,
],
TermSaved::class => [
ClearSitemapamicCache::class,
],
];
Expand Down

0 comments on commit 23b0666

Please sign in to comment.