【问题标题】:Nanoc - Problems with deployment to github pages for css fileNanoc - 部署到 github 页面的 css 文件问题
【发布时间】:2014-10-19 05:44:05
【问题描述】:

所以,试试 nanoc。

已将输出文件夹上传到 github 上的 gh-pages。

css 无法显示其样式。

尝试在规则中添加filter :relativize_paths, :type => :css

再次编译。

它仍然无法正常显示。

我做错了什么?

可以看到页面显示不正常:http://arubyist.github.io/nanoc/

这是规则页面:

compile '*' do
   if item[:extension] == 'css'
   # don’t filter stylesheets
 elsif item.binary?
 # don’t filter binary items
 else
   filter :erb
   layout 'default'
 end
end

 route '*' do
 if item[:extension] == 'css'
 # Write item with identifier /foo/ to /foo.css
 item.identifier.chop + '.css'
 elsif item.binary?
 # Write item with identifier /foo/ to /foo.ext
 item.identifier.chop + '.' + item[:extension]
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
 end
 end

 layout '*', :erb

 compile '/html' do 
   filter :relativize_paths, :type => :html
  end 

 compile '/css' do
   filter :relativize_paths, :type => :css 
  end 

【问题讨论】:

    标签: ruby nanoc github-pages static-site


    【解决方案1】:

    要使其工作,过滤器必须位于编译规则的末尾。对于 html,您必须将其放在 布局语句之后。示例:

    编译'*'做 如果项目[:extension] == 'css' 过滤器 :relativize_paths, :type => :css elif item.binary? # 不要过滤二进制项 别的 过滤器:kramdown 过滤器:erb 布局“默认” 过滤器 :relativize_paths, :type => :html 结尾 结尾

    【讨论】:

    • 嘿,谢谢你告诉我。下次我用 nanocs 摆弄时会这样做。 =)
    【解决方案2】:

    您在顶部的compile '*' 规则是赢得并编译您的所有文件。它甚至从未达到compile '/css' 规则。

    应该这样做:

    compile '*' do
      if item[:extension] == 'css'
        filter :relativize_paths, :type => :css 
      elsif item.binary?
        # don’t filter binary items
      else
        filter :erb
        filter :relativize_paths, :type => :html
        layout 'default'
      end
    end
    
    route '*' do
      if item[:extension] == 'css'
        # Write item with identifier /foo/ to /foo.css
        item.identifier.chop + '.css'
      elsif item.binary?
        # Write item with identifier /foo/ to /foo.ext
        item.identifier.chop + '.' + item[:extension]
      else
        # Write item with identifier /foo/ to /foo/index.html
        item.identifier + 'index.html'
      end
    end
    
    layout '*', :erb
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-20
      • 2012-11-10
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 2020-08-10
      • 2021-02-14
      相关资源
      最近更新 更多