因此,這是我的第一個中間人項目,我正在努力處理中間人如何管理鏈接。Middleman路徑無法在子目錄中工作
事實上,我已經在github頁面上設置了它。我的所有資產都在運作,所以我說得對,但由於網站位於子目錄中,導致每個網頁的路徑都失敗。
基本上root/directoryname/index.html的作品,但每個鏈接都會返回一個目錄,所以我應該有根/目錄名/ page.html我得到root/page.html。
Here, have a link to see it live
這裏是我的config.rb樣子:
# Reload the browser automatically whenever files change
configure :development do
activate :livereload
end
# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
set :css_dir, 'css'
set :js_dir, 'js'
set :images_dir, 'img'
# Build-specific configuration
configure :build do
# For example, change the Compass output style for deployment
activate :minify_css
# Minify Javascript on build
activate :minify_javascript
# Enable cache buster
activate :asset_hash
# Use relative URLs
activate :relative_assets
activate :directory_indexes
# Or use a different image path
# set :http_prefix, "/Content/images/"
end
activate :deploy do |deploy|
deploy.method = :git
# Optional Settings
# deploy.remote = "custom-remote" # remote name or git url, default: origin
# deploy.branch = "custom-branch" # default: gh-pages
# deploy.strategy = :submodule # commit strategy: can be :force_push or :submodule, default: :force_push
end
data.works.each do |item|
proxy "/references/#{item.clean}.html", "/work.html", :locals => { :code => item }, :ignore => true
end
helpers do
# Sets the html class to 'active' when the link url is equal to the current page being viewed.
# Use just like the link_to helper.
# <%= magic_link_to 'Home', '/index.html' %>
def magic_link_to(link, url, opts={})
current_url = current_resource.url
if current_url == url_for(url) || current_url == url_for(url) + "/"
opts[:class] = "active"
end
link_to(link, url, opts)
end
end
而且這裏是我的主菜單的樣子:
<nav id="mainNav">
<ul>
<li id="logo"><% link_to '/index.html' do %><span>ben</span> rajalu<% end %></li>
<li id="homeLink"><%= magic_link_to 'home', '/index.html' %></li>
<li class="divider"></li>
<li><%= magic_link_to 'services', '/services.html' %></li>
<li class="divider"></li>
<li><%= magic_link_to 'références', '/references.html' %></li>
<li class="divider"></li>
<li><%= magic_link_to 'a propos', '/a-propos.html' %></li>
<li class="divider"></li>
<li id="contact"><a href="#" class="offTrigger" data-target="#contactBar">contact</a></li>
</ul>
</nav>
你們有什麼覺得?我錯過了什麼?
作爲2015年12月的,你應該使用,而不是 'magic_link_to' 的link_to「。 –