Ruby on rails Nanoc在github中部署页面时更改基本路径

Ruby on rails Nanoc在github中部署页面时更改基本路径,ruby-on-rails,ruby,github,nanoc,github-pages,Ruby On Rails,Ruby,Github,Nanoc,Github Pages,我有一个使用nanoc构建的简单静态页面应用程序,我想将其部署为github页面 一切进展顺利,除了资产(如css、javascripts)和所有链接通常指向回购的根: 像 /css/style.css 而不是 /docs/css/style.css 在localhost上一切都运行良好,但在发布时失败 我正在使用rake publish将其推送到gh页面 这是我的耙子 require 'nanoc3/tasks' BASE_URL = "http://darko1002001.github.

我有一个使用nanoc构建的简单静态页面应用程序,我想将其部署为github页面

一切进展顺利,除了资产(如css、javascripts)和所有链接通常指向回购的根:

/css/style.css

而不是

/docs/css/style.css

在localhost上一切都运行良好,但在发布时失败

我正在使用rake publish将其推送到gh页面

这是我的耙子

require 'nanoc3/tasks'

BASE_URL = "http://darko1002001.github.com/docs/"

desc "Compile the site"
task :compile do
  `nanoc compile`
end

desc "Publish to http://documentation.getchute.com"
task :publish => [:clean] do
  FileUtils.rm_r('output') if File.exist?('output')

  sh "nanoc compile"

  ENV['GIT_DIR'] = File.expand_path(`git rev-parse --git-dir`.chomp)
  old_sha = `git rev-parse refs/remotes/origin/gh-pages`.chomp
  Dir.chdir('output') do
    ENV['GIT_INDEX_FILE'] = gif = '/tmp/dev.gh.i'
    ENV['GIT_WORK_TREE'] = Dir.pwd
    File.unlink(gif) if File.file?(gif)
    `git add -A`
    tsha = `git write-tree`.strip
    puts "Created tree   #{tsha}"
    if old_sha.size == 40
      csha = `echo 'boom' | git commit-tree #{tsha} -p #{old_sha}`.strip
    else
      csha = `echo 'boom' | git commit-tree #{tsha}`.strip
    end
    puts "Created commit #{csha}"
    puts `git show #{csha} --stat`
    puts "Updating gh-pages from #{old_sha}"
    `git update-ref refs/heads/gh-pages #{csha}`
    `git push origin gh-pages`
  end
end
规则


默认情况下,nanoc生成绝对URL,但您可以使用
relativize\u路径
过滤器使所有URL相对。对于HTML,使用
过滤器:相对化路径,:type=>:HTML
。对于CSS,请使用
:CSS
而不是
:html

干杯


丹尼斯

嘿,丹尼斯。下面是如何生成src的。所以我认为这是一条相对路径,对吗?如果路径以斜线开始,它就是绝对路径。“/images/logo_developer.png”是绝对值,因此解析为而不是。如果运行
relativize_paths
过滤器,则该路径将是相对的,因此它将是例如“./images/logo_developer.png”,这取决于它的引用位置。通过这种方式,你可以构建一个站点,并且可以将它放在你想要的任何子目录中——甚至可以将它移动到不同的位置,而无需重新编译。我还没有找到任何好的例子来做这件事……这个问题的答案就在我的答案里。使用
relativize\u paths
过滤器以相对化HTML和CSS中的路径。您可能希望使用``route'/static/*/'项。identifier.gsub(/\/static\/,'/')。chop``以便在更改文件夹名称时记住更新字符串更改。
compile '/static/*' do
end

compile '/CNAME/' do
end

compile '/feed/' do
  filter :erb
  filter :kramdown, :toc_levels => [2]
end

%w(v3 */).each do |version|
  compile "/changes/#{version}" do
    filter :erb
    filter :kramdown, :toc_levels => [2]
    filter :colorize_syntax,
      :colorizers => {:javascript => :pygmentsrb}
    layout 'changes' if version[0] == '*'
    layout 'default'
  end
end

compile '*' do
  filter :erb
  filter :kramdown, :toc_levels => [2]
  filter :colorize_syntax,
    :colorizers => {:javascript => :pygmentsrb}
  layout 'default'
end

route '/static/*' do
  item.identifier[7..-2]
end

route '/CNAME/' do
  '/CNAME'
end

route '/feed' do
  '/changes.atom'
end

route '*' do
  item.identifier + 'index.html'
end

layout '*', :erb