【问题标题】:Middleman paths not working on subdirectory中间人路径不适用于子目录
【发布时间】:2014-06-19 12:37:55
【问题描述】:

所以,这是我的第一个中间人项目,我正在为中间人如何管理链接而苦苦挣扎。

事实上,我已经在 github 页面上进行了设置。我所有的资产都在工作,所以我做对了,但是由于网站位于子目录中,导致每个页面的路径都失败了。

基本上 root/directoryname/index.html 有效,但每个链接都返回一个目录,所以我应该有 root/directoryname/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 月起,您应该使用 'link_to' 而不是 'magic_link_to'。

标签: html ruby hyperlink path middleman


【解决方案1】:

这是将 Middleman 项目部署到 Github Pages 的一个基本问题。

问题是 Github Pages 将网站部署到子文件夹,所以当你有一个绝对链接时,例如。 G。 &lt;a href="/services.html"&gt;,它总是会指向错误的位置。

您需要将 Middleman 切换到相对链接模式。将此添加到您的config.rb

set :relative_links, true

【讨论】:

  • 非常感谢,确实“这么简单”:)
  • 只要我有足够的代表来启用该功能就会这样做!
猜你喜欢
  • 2015-12-16
  • 2019-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
  • 2016-05-08
  • 1970-01-01
  • 2012-10-18
相关资源
最近更新 更多