HTML、CSS、haml - padrino/sinatra/rails 风格的静态网站生成器布局上的相对链接问题
我正在使用静态站点生成器来创建一个位于我工作中的共享网络文件夹上的站点。对于我的同事来说,这是一个简单的教程网站 - 它没有托管,没有服务器,并且完全静态。我正在使用 the Middleman,这是一个很棒的应用程序。我只需要它来发布一个可以从这样的文件夹中使用的网站。
问题是我的 index.html
和其他 HTML 文件位于不同的文件夹中。网络结构是这样的:
-index.html
+guides/
-guide1.html
-guide2.html
+stylesheets/
+images/
...你明白了。我的导航全部在我的 layout.haml
中,但是,每次我在根 index.html
之外导航时,nab
链接都会获取所有内容搞砸了。如果我使用 (../) 或 (./),它们会查找甚至不存在的文件夹。这是我当前的 layout.haml
导航的一部分(您可以看到我尝试了一些操作):
%nav
%ul
%li.div= link_to 'Home', "index.html"
%li
%a{:href => ("/guides/getting-started.html")} Getting Started
%li= link_to 'Tool Tip 1', "guides/tooltip1.html"
%li= link_to 'Tool Tip 2', "guides/tooltip2.html"
%li= link_to 'Tool Tip 3', "guides/tooltip3.html"
有人建议我在 config.rb 中添加“helpers do”。它应该看起来像这样:
helpers do
def relative_link_to(text, url)
# Get current path
# Get path of url
# Get relative relation between paths
# Pass new data to the original link_to helper
link_to(text, relative_url)
end
end
这就是我迷失的地方,“帮助者做”的部分。有人可以指出我正确的方向或者只是帮助我吗?
I am using a static site generator to make a site that sits on a shared network folder at my job. It's a simple tutorial site for my co-workers—it's not hosted, there's no server, and it's completely static. I am using the Middleman, which is a great app. I just need it to publish a website I can use from a folder like this.
The problem is that my index.html
and other HTML files are in different folders. The web structure is like this:
-index.html
+guides/
-guide1.html
-guide2.html
+stylesheets/
+images/
...you get the idea. My navigation is all in my layout.haml
, however, every time I navigate outside of my root index.html
, the nab
links get all messed up. If I use (../) or (./) they look to folders that don't even exist. Here is a piece of my current layout.haml
nav (you can see I tried a couple of things):
%nav
%ul
%li.div= link_to 'Home', "index.html"
%li
%a{:href => ("/guides/getting-started.html")} Getting Started
%li= link_to 'Tool Tip 1', "guides/tooltip1.html"
%li= link_to 'Tool Tip 2', "guides/tooltip2.html"
%li= link_to 'Tool Tip 3', "guides/tooltip3.html"
It was suggested that I put a 'helpers do' in my config.rb. It should look something like this:
helpers do
def relative_link_to(text, url)
# Get current path
# Get path of url
# Get relative relation between paths
# Pass new data to the original link_to helper
link_to(text, relative_url)
end
end
That's the point where I got lost, the 'helpers do' part. Can someone point me in the right direction or just help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
link_to 'Tool Tip 1', "/guides/tooltip1.html"
怎么样 - 请注意前导斜杠。What about a
link_to 'Tool Tip 1', "/guides/tooltip1.html"
- notice the leading slash.