Skip to content

Commit 48cef46

Browse files
committed
Create dynamic change frequencies
1 parent 91dcfea commit 48cef46

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/framework/src/Framework/Features/XmlGenerators/SitemapGenerator.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,19 @@ protected function getPriority(string $pageClass, string $identifier): string
9595

9696
protected function getChangeFrequency(string $pageClass, string $identifier): string
9797
{
98-
return 'daily';
98+
if ($identifier === '404') {
99+
return 'monthly';
100+
}
101+
102+
if (in_array($pageClass, [BladePage::class, MarkdownPage::class, DocumentationPage::class])) {
103+
return 'daily';
104+
}
105+
106+
if (in_array($pageClass, [MarkdownPost::class, InMemoryPage::class, HtmlPage::class])) {
107+
return 'weekly';
108+
}
109+
110+
return 'weekly';
99111
}
100112

101113
protected function resolveRouteLink(Route $route): string

packages/framework/tests/Feature/SitemapFeatureTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ protected function expected(string $version): string
6767
<url>
6868
<loc>https://example.com/contact.html</loc>
6969
<lastmod>2024-01-01T12:00:00+00:00</lastmod>
70-
<changefreq>daily</changefreq>
70+
<changefreq>weekly</changefreq>
7171
<priority>0.75</priority>
7272
</url>
7373
<url>
7474
<loc>https://example.com/404.html</loc>
7575
<lastmod>2024-01-01T12:00:00+00:00</lastmod>
76-
<changefreq>daily</changefreq>
76+
<changefreq>monthly</changefreq>
7777
<priority>0.25</priority>
7878
</url>
7979
<url>
@@ -91,19 +91,19 @@ protected function expected(string $version): string
9191
<url>
9292
<loc>https://example.com/posts/hello-world.html</loc>
9393
<lastmod>2024-01-01T12:00:00+00:00</lastmod>
94-
<changefreq>daily</changefreq>
94+
<changefreq>weekly</changefreq>
9595
<priority>0.75</priority>
9696
</url>
9797
<url>
9898
<loc>https://example.com/posts/second-post.html</loc>
9999
<lastmod>2024-01-01T12:00:00+00:00</lastmod>
100-
<changefreq>daily</changefreq>
100+
<changefreq>weekly</changefreq>
101101
<priority>0.75</priority>
102102
</url>
103103
<url>
104104
<loc>https://example.com/docs/404.html</loc>
105105
<lastmod>2024-01-01T12:00:00+00:00</lastmod>
106-
<changefreq>daily</changefreq>
106+
<changefreq>monthly</changefreq>
107107
<priority>0.25</priority>
108108
</url>
109109
<url>
@@ -127,13 +127,13 @@ protected function expected(string $version): string
127127
<url>
128128
<loc>https://example.com/docs/search.json</loc>
129129
<lastmod>2024-01-01T12:00:00+00:00</lastmod>
130-
<changefreq>daily</changefreq>
130+
<changefreq>weekly</changefreq>
131131
<priority>0.5</priority>
132132
</url>
133133
<url>
134134
<loc>https://example.com/docs/search.html</loc>
135135
<lastmod>2024-01-01T12:00:00+00:00</lastmod>
136-
<changefreq>daily</changefreq>
136+
<changefreq>weekly</changefreq>
137137
<priority>0.5</priority>
138138
</url>
139139
</urlset>

0 commit comments

Comments
 (0)