Skip to content

Commit

Permalink
Merge pull request #22 from wuifdesign/allow-computed-value
Browse files Browse the repository at this point in the history
Allow computed value for configs
  • Loading branch information
martyf authored Jul 16, 2024
2 parents 0b6c18c + 71b316d commit 1a2dfa1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Support/Sitemapamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ protected function loadEntries(): \Illuminate\Support\Collection
}

// include_xml_sitemap is one of null (when not set, so default to true), then either false or true
$includeInSitemap = $entry->get(config('sitemapamic.mappings.include', 'meta_include_in_xml_sitemap'));
$includeKey = config('sitemapamic.mappings.include', 'meta_include_in_xml_sitemap');
$includeInSitemap = $entry->get($includeKey) ?? $entry->getComputed($includeKey);
if ($includeInSitemap === null || $includeInSitemap == 'default') {
// get the default config, or return true by default
return config('sitemapamic.defaults.'.$entry->collection()->handle().'.include', true);
Expand All @@ -202,19 +203,22 @@ protected function loadEntries(): \Illuminate\Support\Collection
return true;
})->map(function ($entry) {

$changeFreq = $entry->get(config('sitemapamic.mappings.change_frequency', 'meta_change_frequency'));
$changeFreqKey = config('sitemapamic.mappings.change_frequency', 'meta_change_frequency');
$changeFreq = $entry->get($changeFreqKey) ?? $entry->getComputed($changeFreqKey);
if ($changeFreq == 'default') {
// clear back to use default
$changeFreq = null;
}

$priorityKey = config('sitemapamic.mappings.priority', 'meta_priority');

// return the entry as a Sitemapamic URL
return new SitemapamicUrl(
URL::makeAbsolute($entry->url()),
Carbon::parse($entry->get('updated_at'))->toW3cString(),
$changeFreq ?? config('sitemapamic.defaults.'.$entry->collection()->handle().'.frequency',
false),
$entry->get(config('sitemapamic.mappings.priority', 'meta_priority')) ?? config('sitemapamic.defaults.'.$entry->collection()->handle().'.priority',
$entry->get($priorityKey) ?? $entry->getComputed($priorityKey) ?? config('sitemapamic.defaults.'.$entry->collection()->handle().'.priority',
false)
);
})->toArray();
Expand Down

0 comments on commit 1a2dfa1

Please sign in to comment.