Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Created February 2, 2013 22:49
Show Gist options
  • Save tdreyno/4699599 to your computer and use it in GitHub Desktop.
Save tdreyno/4699599 to your computer and use it in GitHub Desktop.
# Store somewhere
class SitemapGenerator
def initialize(app)
@app = app
end
def manipulate_resource_list(resources)
sitemap_builder = ::Middleman::Sitemap::Resource.new(
@app.sitemap,
"sitemap.xml", # The URL
File.join(File.dirname(__FILE__), 'source', 'sitemap.xml.builder') # Path to your template
)
resources << sitemap_builder
resources
end
end
# In your extension register/setup method
app.after_configuration do
sitemap.register_resource_list_manipulator(:sitemap_generator,
SitemapGenerator.new(self),
false)
end
@dhulihan
Copy link

dhulihan commented Feb 4, 2013

Hey Thomas -
I've tried adding this to an example extension I made. However, when I run middleman build --verbose, It appears an additional path to the template is being prefixed onto my specified path:

== Request: /extension_page.html
       error  build/extension_page.html
No such file or directory - /home/dave/middleman-test/source/home/dave/middleman-test/vendor/gems/middleman-example-extension/lib/middleman-example-extension/source/extension_page.md

Here's the code causing this:

# middleman-example-extension/lib/extension_page.rb
extension_page = ::Middleman::Sitemap::Resource.new(
  @app.sitemap,
  "extension_page.html", # The URL
  File.join(File.dirname(__FILE__), 'source', 'extension_page.md') # => should return "middleman-example-extension/source/extension_page.md"
)

So the correct path is getting prefixed with /home/dave/middleman-test/source/. Can you see what I'm doing wrong? I've updated my repo so you can reproduce this on your machine, if you want. Thanks again for the help :) .

@dhulihan
Copy link

dhulihan commented Feb 7, 2013

Update: Thomas fixed this issue in c9290c6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment