如何忽略 Middleman Sitemap 中的页面
How to ignore pages in Middleman Sitemap
我是 Middleman(和 Ruby)的新手,正在制作 HTML 和 XML 站点地图。我已经使用 method.
正确生成了站点地图
<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% pages.each do |p| %>
<url>
<loc>http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%></loc>
<priority>0.7</priority>
</url>
<% end %>
</urlset>
但这是站点内的所有 .html
页面。如何从查询中排除某些页面(门控内容、AB 测试页面等),使它们不包含在站点地图中?
只需在您的 .find_all
块中添加更多条件:
.find_all { |p|
p.source_file.match(/\.html/)
&& p.whatever !== 'something'
}
我是 Middleman(和 Ruby)的新手,正在制作 HTML 和 XML 站点地图。我已经使用 method.
正确生成了站点地图<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% pages.each do |p| %>
<url>
<loc>http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%></loc>
<priority>0.7</priority>
</url>
<% end %>
</urlset>
但这是站点内的所有 .html
页面。如何从查询中排除某些页面(门控内容、AB 测试页面等),使它们不包含在站点地图中?
只需在您的 .find_all
块中添加更多条件:
.find_all { |p|
p.source_file.match(/\.html/)
&& p.whatever !== 'something'
}