【问题标题】:Redirecting Folders in Middleman's config.rb在 Middleman 的 config.rb 中重定向文件夹
【发布时间】:2014-01-27 18:54:16
【问题描述】:

我正在使用静态站点生成器 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 了解如何执行此操作。

提前谢谢你。

【问题讨论】:

    标签: ruby-on-rails ruby middleman


    【解决方案1】:

    如果你修改你的文件模式...

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

    ...您应该在seo 树中获得所有erb 模板。

    然后您需要修改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
    

    【讨论】:

    • 完美!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 2014-11-23
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    相关资源
    最近更新 更多