问题描述
我有一个简单的静态页面应用程序,我用nanoc构建,我想将它部署为github页面。
除了资产像css,javascripts)和所有的链接一般指向回购的根:
like
而不是
在本地主机上一切正常,但失败时发布。
我使用rake publish将它推送到gh-pages。
这是我的Rakefile
需要'nanoc3 / tasks'
BASE_URL =http://darko1002001.github.com/ docs /
desc编译网站
任务:编译完成
`nanoc compile`
结束
desc发布到http://documentation.getchute.com
任务:发布=> [:clean] do
FileUtils.rm_r('output')if File.exist?('output')
shnanoc 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
putsCreated tree#{tsha}
如果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
putsCreated commit#{csha}
puts`git show#{csha} --stat`
puts 从#{old_sha}更新gh页面
`git update-ref refs / heads / gh-pages#{csha}`
`git push origin gh-pages`
end
end
规则
compile'/ static / *'do
end
compile'/ CNAME /'do
end
编译'/ feed /'do
filter:erb
filter:kramdown,:toc_levels => [2]
结束
%w(v3 * /)。
编译/ 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
nanoc默认生成绝对URL,但您可以使用 relativize_paths
过滤器使所有网址相对。对于HTML,请使用 filter:relativize_paths,:type => :HTML
。对于CSS,使用:css
而不是:html
。
干杯
丹尼斯
I have a simple static page app that i have built with nanoc and i want to deploy it as a github page.
Everything goes well except that the assets (like css, javascripts) and all the links in general point to the root of the repo:
like
instead of being
Everything works well on localhost but fails when published.
i am using rake publish to push it to gh-pages.
Here is my Rakefile
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
Rules
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
nanoc generates absolute URLs by default, but you can use the relativize_paths
filter to make all URLs relative. For HTML, use filter :relativize_paths, :type => :html
. For CSS, use :css
instead of :html
.
Cheers
Denis
这篇关于Nanoc在github中部署页面时更改基本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!