-
Notifications
You must be signed in to change notification settings - Fork 18
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 the possibility to exclude a page from being included #4
Comments
Yes, it would be great to have the option to exclude pages! |
Here's what that could look like: #5 |
It's should probably be something like Just to about any confusion with additional plugin, but also to make it 100% clear to the person using MM. |
I agree with @andreamoro! Also it would be great to exclude entire directories in the def in_sitemap?(page)
page.path =~ /\.html/ && !page.data.noindex == true && !(/api/.match(page.path))
end |
@schurig have you already done some implementation to work on top of the plugin? It would be great if you can share the whole bunch of code as I do need it for a project of mine, but I am struggling in time at present. |
Unfortunately not. I'm not using any plugin at the moment. The reason is this issue here - I really need to exclude pages and directories. But I can share the entire code that I'm using at the moment: # sitemap.xml.builder
xml.instruct!
xml.urlset 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
sitemap.resources.select { |page| in_sitemap?(page) }.each do |page|
xml.url do
xml.loc site_url + page.url
xml.loc page.path
xml.lastmod Date.today.to_time.iso8601
xml.changefreq page.data.changefreq || 'monthly'
xml.priority page.data.priority || '0.9'
end
end
end # config.rb
require 'builder'
helpers do
def in_sitemap?(page)
page.path =~ /\.html/ && !page.data.noindex == true && !(/api/.match(page.path))
end
end # Gemfile
gem 'builder' Hope that helps! :) |
@schurig thanks for the code. |
@andreamoro almost! It unfortunately doesn't generate a sitemap.xml.gz file. |
@andreamoro I was concerned about the frontmatter options colliding as well. Actually, I think it would be best to just namespace them all, like this:
That way, all options are accessible from the sitemap. namespace. Since this would be a breaking change, it would probably be best to release it with a new major version, so people who are updating minor/patch versions don't get hosed when all their frontmatter options suddenly stop working. |
@bentoncreation make absolutely sense, and it allows options for expanding the project. E.g. assuming you want to include an image in the sitemap, by adding something like the following bits it can be easily parsed and appended in the page.
|
@andreamoro Yeah, totally! |
So we have to wait for @stantonjr to code this bit :) |
@schurig I was thinking about how you might ignore whole directories and I'm wondering if this makes sense. In your config, have an ignored_paths option, like so:
And then, when getting pages (in my proposed private get_pages method), filter out those that match anything found in ignored_paths. |
@bentoncreation sounds good! But what about single pages? I think there are situations where you want to exclude sites without writing
into them. activate :sitemap do |sitemap|
sitemap.hostname = "http://www.mysite.com"
sitemap.ignore = %r{^/api/contact_form.php*}
end |
@schurig What kind of situations are you thinking of? I think your .php file example would already be excluded because the sitemap builder is only looking at .html files. |
@bentoncreation oh, you're right! However, I think it would still be good to let the user decide whether he wants to go into his |
@schurig Yeah, I could see that. I wouldn't normally think it was a good the idea to have multiple ways to set the same option, but maybe it's not a big deal in this case. If I get my other pull request accepted I may look at adding this concept as well. |
I believe there should not be a method to remove page that is clashing with another. But that's my idea. |
Not all pages should be included in the sitemap. E.g. the thank-you page
For this reason it would be great having a tag in the YAML that would be recognised as way to avoid such inclusion.
The text was updated successfully, but these errors were encountered: