html – Middleman路径不在子目录上工作

前端之家收集整理的这篇文章主要介绍了html – Middleman路径不在子目录上工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

所以,这是我的第一个中间人项目,我正在努力解决中间人管理链接的问题.

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

基本上root / directoryname / index.html有效但每个链接都返回一个目录,所以我应该有root / directoryname / page.html我得到root / page.html.

Here,have a link to see it live

这是我的config.rb的样子:

  1. # Reload the browser automatically whenever files change
  2. configure :development do
  3. activate :livereload
  4. end
  5. # Methods defined in the helpers block are available in templates
  6. # helpers do
  7. # def some_helper
  8. # "Helping"
  9. # end
  10. # end
  11. set :css_dir,'css'
  12. set :js_dir,'js'
  13. set :images_dir,'img'
  14. # Build-specific configuration
  15. configure :build do
  16. # For example,change the Compass output style for deployment
  17. activate :minify_css
  18. # Minify Javascript on build
  19. activate :minify_javascript
  20. # Enable cache buster
  21. activate :asset_hash
  22. # Use relative URLs
  23. activate :relative_assets
  24. activate :directory_indexes
  25. # Or use a different image path
  26. # set :http_prefix,"/Content/images/"
  27. end
  28. activate :deploy do |deploy|
  29. deploy.method = :git
  30. # Optional Settings
  31. # deploy.remote = "custom-remote" # remote name or git url,default: origin
  32. # deploy.branch = "custom-branch" # default: gh-pages
  33. # deploy.strategy = :submodule # commit strategy: can be :force_push or :submodule,default: :force_push
  34. end
  35. data.works.each do |item|
  36. proxy "/references/#{item.clean}.html","/work.html",:locals => { :code => item },:ignore => true
  37. end
  38. helpers do
  39. # Sets the html class to 'active' when the link url is equal to the current page being viewed.
  40. # Use just like the link_to helper.
  41. # <%= magic_link_to 'Home','/index.html' %>
  42. def magic_link_to(link,url,opts={})
  43. current_url = current_resource.url
  44. if current_url == url_for(url) || current_url == url_for(url) + "/"
  45. opts[:class] = "active"
  46. end
  47. link_to(link,opts)
  48. end
  49. end

这是我的主菜单的样子:

你们有什么感想 ?我错过了什么?

最佳答案
这是将Middleman项目部署到Github Pages的基本问题.

问题是Github Pages将网站部署到子文件夹,所以当你有一个绝对链接时,e. G. < a href =“/ services.html”>,它将始终指向错误的位置.

您需要将Middleman切换到相对链接模式.将其添加到config.rb:

  1. set :relative_links,true

猜你在找的HTML相关文章