I’ve taken a first stab at writing a sitemap.xml generator.
Very cool. This is something that might be useful in core or as an extension.
I can take a stab at making an extension of it. But I’m unsure on one thing: is the tutorial on how to make extensions located at http://middlemanapp.com/advanced/custom/ current, or has the syntax changed? (I’ve seen something about class based extensions.)
What is the advantage of having it as an extension instead of as a page to place in the source folder? The possibility to set the base url and update frequency in config.rb obviously, but is there anything else?
If you move it to core, please feel free to use and change the code any way you like.
One idea, but a bit to advanced for me to implement, is to define an interface for extensions with dynamic pages to implement. The sitemap could then use to ask them about when the content was last modified. (For example, the blog module would then for the front page answer with the date of the latest blog post, the newest post in the category for a category front page, etc.)
The advantage of an extension is that this file very rarely needs to be edited. It’s an interface for computers so computers should have no problem generating it. It only really needs a couple of config options.
The “Class-based extensions” or, as I’m going to start calling them, “v4 extensions” are a more sandboxed form of extension that will be included in v3.1 and made the default in v4.
They include an interface for common tasks, such as sitemap stuff. Here’s an excerpt of the asset_hash
extension in v3.1:
class Middleman::Extensions::AssetHash < ::Middleman::Extension
option :exts, %w(.jpg .jpeg .png .gif .js .css .otf .woff .eot .ttf .svg), "List of extensions that get asset hashes appended to them."
def after_configuration
# ...
end
def manipulate_resource_list(resources)
# ...
end
end
I’ve started to transfer this into an extension.
But I have trouble doing the equivalent of page "/sitemap.xml", :layout => false
from inside the extension.
I’ve tried doing it when adding the page to the store, with Resource.new
, but I’m not sure I’m doing it the right way. I assume the third parameter is to point at the physical source file – in my case, the sitemap.xml in my gem. Or?
# A Sitemap Manipulator
def manipulate_resource_list(resources)
p = ::Middleman::Sitemap::Resource.new(
@app.sitemap,
'sitemap.xml' ,
"#{File.dirname(__FILE__)}/template/source/sitemap.xml.builder"
)
resources
end
Thanks for this! This is an amazing tool.
At this point I think it requires a bit more configuration than should be necessary, but I’m not sure of the limitations when dealing with Middleman itself. I’d be happy to jump in and help with anything you might need though.
Thank you.
At the moment I’m actually stuck on an issue that I believe has a simple solution – once you know it.
How do I add the sitemap.xml
page to the site. See my earlier question.
maybe you could use the dynamic page feature and define a proxy for this file?
Hey man, just used your gist, seems to work perfectly, thanks for posting this.
That is what I’m trying to do.
My problem is, that a dynamic page requires a template, and I have not managed to understand how to use a template provided by an extension.
(When I have the template in the source
directory everything works fine, so I just have to solve this detail to make this into an extension.)