Question

I'm using the static site generator Middleman to build my site. We currently have landing pages that we proxy via config.rb as such:

# landing page template directories to redirect
landingpage_seo_templates = Dir['source/landingpages/seo/*.erb']

# point all landingpage/seo templates to the root
landingpage_seo_templates.map! do |tpl_name|
  tpl_name = File.basename(tpl_name).gsub(/.erb$/, '')
  proxy "/#{tpl_name}/index.html", "/landingpages/seo/#{tpl_name}.html", :ignore => true
end

This points all of the files in a directory from /landingpages/seo/{filename}.erb to the /{filename}.erb when the site is built. However, this doesn't work for sub-folders.

My question is how would I modify this script to render the sub-folders. For examples I would like files in /landingpages/seo/foo/{filename}.erb to render to /foo/{filename}.erb

I know how to do this via .htaccess, however I'd like to learn how to do this via config.rb.

Thank you in advance.

Était-ce utile?

La solution

If you modify your file pattern ...

landingpage_seo_templates = Dir['source/landingpages/seo/**/*.erb']

... you should get all erb templates in the seo tree.

You then need to modify the tpl_name computation (there probably is a smarter/shorter way for that):

# point all landingpage/seo templates to the root
landingpage_seo_templates.map! do |tpl_name|
  tpl_name = tpl_name.gsub(/.erb$/, '')
  tpl_name = tpl_name.gsub(/source\/landingpages\/seo\//, '')
  proxy "/#{tpl_name}/index.html", "/landingpages/seo/#{tpl_name}.html", :ignore => true
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top