2014-05-02 13 views
5

To jest mój pierwszy pośredni projekt i walczę z tym, jak pośrednik zarządza łączami.Ścieżki pośredników nie działają w podkatalogu

Tak się składa, że ​​ustawiłem go na stronie github. Wszystkie moje zasoby działają, więc mam rację, ale ścieżki prowadzące do każdej strony zawodzą, ponieważ witryna znajduje się w podkatalogu.

Zasadniczo root/nazwa katalogu/index.html działa, ale każdy link sięga jednego katalogu, więc gdzie powinienem mieć katalog główny/nazwa katalogu/strona.html Dostaję root/page.html.

Here, have a link to see it live

Oto co moja config.rb wygląda następująco:

# 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 

A oto co moim głównym menu wygląda następująco:

<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> 

Co myślicie? Co przeoczyłem?

+0

Począwszy od grudnia 2015 roku, należy użyć 'link_to' zamiast 'magic_link_to'. –

Odpowiedz

10

To podstawowy problem z wdrażaniem projektów pośredników do stron Github.

Problem polega na tym, że strony Github wdrażają witryny internetowe w podfolderach, więc jeśli masz bezwzględny link, np. sol. <a href="/services.html">, zawsze wskaże niewłaściwą lokalizację.

Musisz zmienić Middleman na względny tryb linków. Dodaj to do twojej config.rb:

set :relative_links, true 
+0

Wielkie dzięki, to było rzeczywiście "takie proste" :) – benBecker

+0

Nie zapomnij o przegłosowaniu. : P –

+0

Zrobię tak szybko, jak tylko dostanę wystarczającą ilość powtórzeń, aby włączyć funkcję! – benBecker