statonjr / middleman-sitemap

A Middleman extension to create a sitemap for your Middleman site
MIT License
22 stars 18 forks source link

Error when building sitemap based on dynamic directories #1

Open lunks opened 10 years ago

lunks commented 10 years ago

Hi, I have the following on my config.rb:

data.companies.each do |name, company|
  proxy "/companies/#{name}/index.html", "/company_page.html",
    locals: { company: company }
end

Whenever I run middleman build, when trying to build the sitemap I get:

/opt/boxen/rbenv/versions/2.1.0/lib/ruby/2.1.0/uri/generic.rb:824:in `check_path': bad component(expected absolute path component): /companies/01zv/.html (URI::InvalidComponentError)
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/2.1.0/uri/generic.rb:871:in `path='
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/middleman-sitemap-62a9ba786be5/lib/middleman-sitemap/extension.rb:95:in `urlencode'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/middleman-sitemap-62a9ba786be5/templates/sitemap.xml.erb:5:in `block (2 levels) in singleton class'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/middleman-sitemap-62a9ba786be5/templates/sitemap.xml.erb:3:in `each'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/middleman-sitemap-62a9ba786be5/templates/sitemap.xml.erb:3:in `block in singleton class'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/middleman-sitemap-62a9ba786be5/templates/sitemap.xml.erb:-5:in `instance_eval'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/middleman-sitemap-62a9ba786be5/templates/sitemap.xml.erb:-5:in `singleton class'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/middleman-sitemap-62a9ba786be5/templates/sitemap.xml.erb:-7:in `__tilt_70131942349800'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/tilt-1.4.1/lib/tilt/template.rb:170:in `call'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/tilt-1.4.1/lib/tilt/template.rb:170:in `evaluate'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'

PS: Using master to build.

statonjr commented 10 years ago

The error indicates that the URI is invalid. I ran into this issue, too, and had to encode the names before the URI library will accept it. You may want to try htmlentities: https://github.com/threedaymonk/htmlentities

lunks commented 10 years ago

The problem seems to be that encoding this URL (which include backslashes) generates an invalid URI in the end.

i.e. /companies/01zv/ becomes what you see in the output.