netlify-plugin-sitemap icon indicating copy to clipboard operation
netlify-plugin-sitemap copied to clipboard

Sitemap Page Exclusions Not Working

Open devonbeard opened this issue 2 years ago • 3 comments

Hey Folks,

I've been trying to exclude paths from our sitemap using this plugin. I'm trying to have these subfolders not show up on the sitemap:

  • /research/briefs
  • /research/notes
  • /research/

Here are examples of paths I've tried with no luck:

Test 1 (didn't work): ​[[plugins]] package = "@netlify/plugin-sitemap"

[plugins.inputs] buildDir = "public" exclude = [ # By Glob pattern './research//', './research/briefs/' './research/notes/' ] ​ ​Test 2 (didn't work): ​[[plugins]] package = "@netlify/plugin-sitemap"

[plugins.inputs] buildDir = "public" exclude = [ # By Glob pattern './public/research//', './public/research/briefs/' './public/research/notes/' ]

Test 3

exclude = [ # By Glob pattern '//briefs/', '//notes/', '/research//**', ]

Any thoughts on how I can get this to work?

devonbeard avatar Sep 04 '22 12:09 devonbeard

Hey Devon,

I tested this out in a test project using a structure like this:

.
├── netlify.toml
└── public/
    ├── index.html
    ├── blog/
    │   └── index.html
    └── research/
        ├── index.html
        ├── notes/
        │   ├── index.html
        │   └── note-1/
        │       └── index.html
        └── briefs/
            └── index.html

And using the following config

[[plugins]]
package = "@netlify/plugin-sitemap"

  [plugins.inputs]
  buildDir = "public"
  exclude = [
    './public/research/**',
  ]

Gave me a sitemap like this

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
  xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
  xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
  <url>
    <loc>https://addepar-sitemap-test.netlify.app/</loc>
    <lastmod>2022-09-19T23:51:42Z</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://addepar-sitemap-test.netlify.app/blog</loc>
    <lastmod>2022-09-20T00:02:48Z</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

i.e. that pattern excludes anything in the research folder. If you wanted to only exclude certain directories in the research folder you could do that like this

Folder structure:

.
├── netlify.toml
└── public/
    ├── index.html
    ├── blog/
    │   └── index.html
    └── research/
        ├── index.html
        ├── notes/
        │   ├── index.html
        │   └── note-1/
        │       └── index.html
        ├── briefs/
        │   └── index.html
        └── public-whitepapers/
            └── index.html

netlify.toml:

[[plugins]]
package = "@netlify/plugin-sitemap"

  [plugins.inputs]
  buildDir = "public"
  exclude = [
    './public/research/*',
    './public/research/briefs/**',
    './public/research/notes/**',
  ]

sitemap.xml:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
  xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
  xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
  <url>
    <loc>https://addepar-sitemap-test.netlify.app/</loc>
    <lastmod>2022-09-19T23:51:42Z</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://addepar-sitemap-test.netlify.app/blog</loc>
    <lastmod>2022-09-20T00:02:48Z</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://addepar-sitemap-test.netlify.app/research/public-whitepapers</loc>
    <lastmod>2022-09-20T00:08:22Z</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

Let me know if that kind of config works for you

chrishannaby avatar Sep 20 '22 00:09 chrishannaby

@devonbeard can this be closed after the changes we made yesterday?

chrishannaby avatar Sep 28 '22 15:09 chrishannaby

Still experiencing this issue:

[[plugins]]
  package = "@netlify/plugin-sitemap"
  [plugins.inputs]
  buildDir = "public"
  changeFreq = "daily"
  prettyURLs = true
  trailingSlash = true
  exclude = [
    '_gatsby/slices/_gatsby-scripts-1/',
    '/_gatsby/slices/_gatsby-scripts-1/',
    './public/_gatsby/slices/_gatsby-scripts-1/', 
    '**/_gatsby/slices/_gatsby-scripts-1/', 
    '**/**/_gatsby/slices/_gatsby-scripts-1/',
]
Where sitmap.xml still references this file.
Also seem strange to point to a framework related library file as such.

UPDATE: this entry seemed to have fixed the issue: exclude = [ '**/**/_gatsby/', ]

colinrim avatar Aug 17 '23 22:08 colinrim