Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new sitemap for images to resolve indexing issues with webp images #1389

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
54 changes: 51 additions & 3 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const agoliaQueries = require('./src/queries/agolia');
const rssFeedPlugin = require('./src/gatsby/rssFeedPlugin');
const theme = require('./src/theme');
const GATSBY_PLUGIN_CSP_DIRECTIVES = require('./src/gatsby/cspDirectives');
const { getSrc } = require('gatsby-plugin-image');

const SITE_TITLE = 'Roadie';

Expand Down Expand Up @@ -58,7 +59,7 @@ const getContentfulOptions = () => {
};

// These paths are blocked from search engine indexing and search engine access.
const DISLALLOW_LIST = [
const DISALLOW_LIST = [
'/purchase/',
'/purchase/success/',
'/tailwind/404/',
Expand Down Expand Up @@ -209,7 +210,54 @@ module.exports = {
{
resolve: 'gatsby-plugin-sitemap',
options: {
excludes: DISLALLOW_LIST,
output: '/sitemap.xml',
excludes: DISALLOW_LIST,
resolveSiteUrl: () => getSiteUrl(),
query: `
{
allSitePage {
nodes {
path
}
}
allFile(filter: { extension: { regex: "/(jpg|jpeg|png|gif)/" } }) {
nodes {
publicURL
name
childImageSharp {
gatsbyImageData
}
}
}
}
`,
resolvePages: ({ allSitePage: { nodes: allPages }, allFile: { nodes: allImages } }) => {
return allPages.map((page) => {
const images = allImages
.filter((image) => page.path.includes(image.name))
.map((image) => ({
url: image.publicURL, // Use publicURL as a fallback
title: image.name,
gatsbyImageData: image.childImageSharp
? getSrc(image.childImageSharp.gatsbyImageData)
: null, // Check for gatsbyImageData
}))
.filter((image) => image.gatsbyImageData); // Filter out images without gatsbyImageData

return { ...page, images };
});
},
serialize: ({ path, images }) => {
return {
url: path,
changefreq: 'daily',
priority: 0.7,
images: images.map((image) => ({
url: image.url,
title: image.title,
})),
};
},
},
},

Expand All @@ -221,7 +269,7 @@ module.exports = {
policy: [
{
userAgent: '*',
disallow: DISLALLOW_LIST,
disallow: DISALLOW_LIST,
},
],
},
Expand Down
Loading