自定义站点地图生成

问题描述

我使用这个库创建了站点地图 https://github.com/spatie/laravel-sitemap 但我不想要 changefreq 信息。如何禁用。在存储库中找不到

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>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...