Nanoc - 部署到gssub页面的css文件的问题

时间:2014-08-26 01:25:04

标签: ruby nanoc github-pages static-site

所以,试试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 

3 个答案:

答案 0 :(得分:0)

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

compile '*' do
  if item[:extension] == 'css'
    filter :relativize_paths, :type => :css 
  elsif item.binary?
    # don’t filter binary items
  else
    filter :kramdown
    filter :erb
    layout 'default'
    filter :relativize_paths, :type => :html
  end
end

答案 1 :(得分:-1)

您将生成的网站上传到子文件夹" nanoc"而不是服务器上的Web空间的根,并且生成的文件的输出路径需要反映这一点。否则,生成的HTML将包含指向/stylesheet.css样式表的链接,而不是其正确的位置/nanoc/stylesheet.css,这似乎就是这里发生的事情。

尝试将输出路径前缀声明为Rules文件顶部的常量,

OUTPUT_PATH_PREFIX = '/nanoc'

并将其包含在您生成的所有输出路径中:

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

重新生成网站并上传输出文件夹的内容,该文件夹现在包含一个" nanoc"子文件夹,到服务器上的根文件夹,我相信该网站将正确显示

答案 2 :(得分:-1)

顶部的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