middleman-sitemap icon indicating copy to clipboard operation
middleman-sitemap copied to clipboard

Error when building sitemap based on dynamic directories

Open lunks opened this issue 10 years ago • 2 comments

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.

lunks avatar Mar 29 '14 01:03 lunks

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

statonjr avatar Mar 29 '14 16:03 statonjr

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.

lunks avatar Mar 29 '14 18:03 lunks