Skip to content

Commit

Permalink
Statamic 5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
martyf committed May 10, 2024
1 parent 0db4c52 commit cea40ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.DS_Store
/node_modules
vendor
composer.lock
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

<!-- statamic:hide -->

![Statamic 3.3+](https://img.shields.io/badge/Statamic-3.3+-FF269E?style=for-the-badge&link=https://statamic.com)
![Statamic 4.0](https://img.shields.io/badge/Statamic-4.0-FF269E?style=for-the-badge&link=https://statamic.com)
![Statamic 5.0](https://img.shields.io/badge/Statamic-5.0-FF269E?style=for-the-badge&link=https://statamic.com)
[![Sitemapamic on Packagist](https://img.shields.io/packagist/v/mitydigital/sitemapamic?style=for-the-badge)](https://packagist.org/packages/mitydigital/sitemapamic/stats)

---

<!-- /statamic:hide -->

> Sitemapamic is a XML sitemap generator for Statamic 3.3, 4 and 5
> Sitemapamic is a XML sitemap generator for Statamic
Sitemapamic creates a sitemap.xml file for your Statamic site, and includes:

Expand All @@ -27,8 +25,8 @@ Sitemapamic creates a sitemap.xml file for your Statamic site, and includes:

Sitemapamic requires:

- Statamic 3.3, 4 or 5
- PHP 8.1+
- Statamic 5
- PHP 8.2+

## Documentation

Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
}
],
"require": {
"php": "^8.1",
"statamic/cms": "^3.3|^4.0|^5.0"
"php": "^8.2",
"statamic/cms": "^5.0"
},
"extra": {
"statamic": {
Expand All @@ -31,5 +31,10 @@
"MityDigital\\Sitemapamic\\ServiceProvider"
]
}
},
"config": {
"allow-plugins": {
"pixelfear/composer-dist-plugin": true
}
}
}
15 changes: 8 additions & 7 deletions src/Support/Sitemapamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ protected function loadEntries(): \Illuminate\Support\Collection
protected function loadCollectionTerms(): \Illuminate\Support\Collection
{
// get the current site key based on the url
$site = 'default';
foreach (config('statamic.sites.sites', []) as $key => $props) {
if ($props['url'] == url('/')) {
$site = $key;
$site = Site::default();
foreach (Site::all() as $key => $props) {
if ($props->url() == url('/')) {
$site = $props;
break;
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ protected function loadCollectionTerms(): \Illuminate\Support\Collection
}

// site is not configured, so exclude
if (!$term->collection()->sites()->contains($site)) {
if (!$term->collection()->sites()->contains($site->handle())) {
return false;
}

Expand All @@ -282,7 +282,7 @@ protected function loadCollectionTerms(): \Illuminate\Support\Collection
}

return true; // this far, accept it
})->map(function ($term) {
})->map(function ($term) use ($site) {
// get the term mod date
$lastMod = $term->get('updated_at');

Expand All @@ -308,7 +308,8 @@ protected function loadCollectionTerms(): \Illuminate\Support\Collection


// get the site URL, or the app URL if its "/"
$siteUrl = config('statamic.sites.sites.'.$term->locale().'.url');
//$siteUrl = config('statamic.sites.sites.'.$term->locale().'.url');
$siteUrl = $site->url();
if ($siteUrl == '/') {
$siteUrl = config('app.url');
}
Expand Down

0 comments on commit cea40ea

Please sign in to comment.