【问题标题】:Middleman Output Path中间人输出路径
【发布时间】:2013-08-01 16:02:11
【问题描述】:

为清楚起见进行编辑:

我想知道是否可以为中间人构建中的文件设置输出路径。出于组织目的,我想将一种类型的页面分组到一个文件夹中,以使其远离主源目录。但是在构建/服务器上,我希望它呈现到不同的路径:

/source
    index.html
    /landingpages
        landingpage1.html
        landingpage2.html

我在我的配置文件中启用了:directory_indexes 希望能够将landingpage 中的文件输出到根目录:

/build
    index.html
    /landingpage1
        index.html
    /landingpage2
        index.html

是否有可能使用 config.rb 文件以某种方式实现这一点,并且仍然可以正确显示在站点地图中?我宁愿不必使用 .htaccess 来执行此操作

谢谢

【问题讨论】:

    标签: ruby middleman


    【解决方案1】:

    我在当前项目中使用的一种技术是基于代理的,也应该可以解决您的问题:

    landingpage_templates = Dir['source/landingpages/*.html']
    
    landingpage_templates.map! do |tpl_name|
      tpl_name = File.basename(tpl_name).gsub(/.html$/, '')
      proxy "/#{tpl_name}/index.html", "/landingpages/#{tpl_name}.html", :ignore => true
    end
    

    【讨论】:

    • 这非常有效。我只是拿了 :ignore 部分,因为我希望它们被索引。非常感谢!
    • 不客气。很高兴将其记录在某处,例如在这里 SO :)
    【解决方案2】:

    你应该可以做这样的事情:

    page "/file1/index.html",  :proxy => "/somefolder/file1.html"
    page "/file2/index.html",  :proxy => "/somefolder/file2.html"
    

    我认为您最好使用using directory indexes 来组织您的文件,例如:

    /source
        index.html
        file1.html
        file2.html
    

    在你的config.rb

    activate :directory_indexes
    

    【讨论】:

    • 这不适用于单个文件,我需要重定向整个目录。
    • 您需要提供更多关于您想要实现的目标的信息。您能否为您的问题提供更多背景信息?
    • 感谢您的澄清,但我认为您使用的工具有误。
    猜你喜欢
    • 2013-09-10
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多