【发布时间】:2020-01-17 01:24:34
【问题描述】:
我知道我可以在options 对象中使用exclude 数组排除带有gatsby-plugin-sitemap 的网址,但是有没有办法要求所有网址都有一些字符串?主要是要求添加到站点地图的网址包含en-us 或es-us
{
resolve: `gatsby-plugin-sitemap`,
options: {
exclude: [`all urls must contain "en-us" or "es-us"`],
},
},
谢谢!
更新!!
感谢@MarkoCen,我能够得到这个工作。我只是使用正则表达式在我的站点地图中添加了我想要的 URL。如果有人感兴趣,这是代码。请注意,我必须使用这种方法manually exclude /404:
{
resolve: `gatsby-plugin-sitemap`,
options: {
query: `
{
site {
siteMetadata {
siteUrl
}
}
allSitePage {
edges {
node {
path
}
}
}
}`,
serialize: ({ site, allSitePage }) => {
const links = [];
for (let i = 0; i < allSitePage.edges.length; i++) {
const { path } = allSitePage.edges[i].node;
if (
/products|404|unsupported|account/.test(path)
) {
continue;
} else if (/en-us|es-us/.test(path)) {
links.push({
url: site.siteMetadata.siteUrl + path,
changefreq: 'daily',
priority: 0.8,
});
}
}
return links;
},
},
},
【问题讨论】:
标签: gatsby sitemap.xml