自定义站点地图生成
Customized Sitemap Generate
我使用这个库创建了站点地图https://github.com/spatie/laravel-sitemap
但我不希望 changefreq info.how 到 disable.can 在存储库中找不到
SitemapGenerator::create(url('/'))->writeToFile(public_path('sitemap.xml'));
结果
<url>
<loc>http://the-frenemy.local</loc>
<lastmod>2021-04-16T00:00:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.9</priority>
</url>
再更改设置优先级为 1 只有主页..所有其他页面设置为 0.9
发布资源视图
然后编辑文件:https://github1s.com/spatie/laravel-sitemap/blob/HEAD/resources/views/url.blade.php
<url>
@if (! empty($tag->url))
<loc>{{ url($tag->url) }}</loc>
@endif
@if (count($tag->alternates))
@foreach ($tag->alternates as $alternate)
<xhtml:link rel="alternate" hreflang="{{ $alternate->locale }}" href="{{ url($alternate->url) }}" />
@endforeach
@endif
@if (! empty($tag->lastModificationDate))
<lastmod>{{ $tag->lastModificationDate->format(DateTime::ATOM) }}</lastmod>
@endif
// remove this
@if (! empty($tag->changeFrequency))
<changefreq>{{ $tag->changeFrequency }}</changefreq>
@endif
// remove this
@if (! empty($tag->priority))
<priority>{{ number_format($tag->priority,1) }}</priority>
@endif
</url>
我使用这个库创建了站点地图https://github.com/spatie/laravel-sitemap 但我不希望 changefreq info.how 到 disable.can 在存储库中找不到
SitemapGenerator::create(url('/'))->writeToFile(public_path('sitemap.xml'));
结果
<url>
<loc>http://the-frenemy.local</loc>
<lastmod>2021-04-16T00:00:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.9</priority>
</url>
再更改设置优先级为 1 只有主页..所有其他页面设置为 0.9
发布资源视图
然后编辑文件:https://github1s.com/spatie/laravel-sitemap/blob/HEAD/resources/views/url.blade.php
<url>
@if (! empty($tag->url))
<loc>{{ url($tag->url) }}</loc>
@endif
@if (count($tag->alternates))
@foreach ($tag->alternates as $alternate)
<xhtml:link rel="alternate" hreflang="{{ $alternate->locale }}" href="{{ url($alternate->url) }}" />
@endforeach
@endif
@if (! empty($tag->lastModificationDate))
<lastmod>{{ $tag->lastModificationDate->format(DateTime::ATOM) }}</lastmod>
@endif
// remove this
@if (! empty($tag->changeFrequency))
<changefreq>{{ $tag->changeFrequency }}</changefreq>
@endif
// remove this
@if (! empty($tag->priority))
<priority>{{ number_format($tag->priority,1) }}</priority>
@endif
</url>