2014-01-27 11 views
0

我正在使用靜態網站生成器Middleman構建我的網站。目前,我們的目標網頁,我們通過config.rb代理這樣:該網站是建立在在Middleman的config.rb中重定向文件夾

# 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 

這點所有的文件從/landingpages/seo/{filename}.erb目錄到/{filename}.erb。但是,這不適用於子文件夾。

我的問題是我將如何修改此腳本來呈現子文件夾。對於例子,我想文件/landingpages/seo/foo/{filename}.erb渲染到/foo/{filename}.erb

我知道如何通過.htaccess做到這一點,但是我想了解如何通過config.rb做到這一點。

預先感謝您。

回答

1

如果修改文件模式...

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

...你應該得到的所有erb模板在seo樹。

然後,您需要修改tpl_name計算(有可能是一個更聰明/更短的方式爲):

# 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 
+0

完美!非常感謝你。 – SkyOut