gpt4 book ai didi

breadcrumbs - 在 Jekyll 网站上实现面包屑的好方法有哪些?

转载 作者:行者123 更新时间:2023-12-03 11:20:28 29 4
gpt4 key购买 nike

我知道 http://raphinou.github.com/jekyll-base/ 中有单级面包屑。但我正在寻找一些获得 的好方法Jekyll 站点上的面包屑,当目录达到四或五级深度时 .

(是的,我很清楚 Jekyll 主要是一个博客引擎,也许我不应该将它用于通用网站,尤其是具有许多目录级别的网站。我也知道 http://octopress.org 但还没有找到一个合适的插件。)

主要基于 http://forums.shopify.com/categories/2/posts/22172我想出了以下面包屑的 Jekyll 布局,您可以在 http://crimsonfu.github.com/members/pdurbin 上看到它的变体。 .您应该会在顶部看到面包屑“ home » members » ”。

这是我的布局。是的,它很丑。我对Liquid的研究不多。你能推荐一个更好的方法吗?

<html>
<head>
<title>{{ page.title }}</title>
<style type="text/css">
#bread ul {
padding-left: 0;
margin-top: 2px;
margin-bottom: 2px;
}
#bread ul li {
display: inline;
font-size: 70%;
}
</style>
</head>
<body>
<div id="bread">
<ul>

{% assign url = {{page.url}} %}
{% assign delimiter = '/' %}
{% capture allparts %}{{ url | replace: delimiter, ' ' }}{% endcapture %}

{% capture myFirstWord %}{{ allparts | truncatewords: 1 | remove: '...' }}{% endcapture %}
{% capture minusFirst %}{{ allparts | replace_first: myFirstWord, '' }}{% endcapture %}

{% capture mySecondWord %}{{ minusFirst | truncatewords: 1 | remove: '...' }}{% endcapture %}
{% capture minusSecond %}{{ minusFirst | replace_first: mySecondWord, '' }}{% endcapture %}

{% capture myThirdWord %}{{ minusSecond | truncatewords: 1 | remove: '...' }}{% endcapture %}
{% capture minusThird %}{{ minusSecond | replace_first: myThirdWord, '' }}{% endcapture %}

{% capture myFourthWord %}{{ minusThird | truncatewords: 1 | remove: '...' }}{% endcapture %}
{% capture minusFourth %}{{ minusThird | replace_first: myFourthWord, '' }}{% endcapture %}

{% capture myFifthWord %}{{ minusFourth | truncatewords: 1 | remove: '...' }}{% endcapture %}

{% if myFirstWord contains '.html' %}
<li><a href="/">home</a> &nbsp; </li>
{% elsif mySecondWord contains '.html' %}
<li><a href="/">home</a> &#187; </li>
{% unless mySecondWord == 'index.html' %}
<li><a href="/{{myFirstWord}}">{{myFirstWord}}</a> &#187; </li>
{% endunless %}
{% elsif myThirdWord contains '.html' %}
<li><a href="/">home</a> &#187; </li>
<li><a href="/{{myFirstWord}}">{{myFirstWord}}</a> &#187; </li>
{% unless myThirdWord == 'index.html' %}
<li><a href="/{{myFirstWord}}/{{mySecondWord}}">{{mySecondWord}}</a> &#187; </li>
{% endunless %}
{% elsif myFourthWord contains '.html' %}
<li><a href="/">home</a> &#187; </li>
<li><a href="/{{myFirstWord}}">{{myFirstWord}}</a> &#187; </li>
<li><a href="/{{myFirstWord}}/{{mySecondWord}}">{{mySecondWord}}</a> &#187; </li>
{% unless myFourthWord == 'index.html' %}
<li><a href="/{{myFirstWord}}/{{mySecondWord}}/{{myThirdWord}}">{{myThirdWord}}</a> &#187; </li>
{% endunless %}
{% elsif myFifthWord contains '.html' %}
<li><a href="/">home</a> &#187; </li>
<li><a href="/{{myFirstWord}}">{{myFirstWord}}</a> &#187; </li>
<li><a href="/{{myFirstWord}}/{{mySecondWord}}">{{mySecondWord}}</a> &#187; </li>
<li><a href="/{{myFirstWord}}/{{mySecondWord}}/{{myThirdWord}}">{{myThirdWord}}</a> &#187; </li>
{% unless myFifthWord == 'index.html' %}
<li><a href="/{{myFirstWord}}/{{mySecondWord}}/{{myThirdWord}}/{{myFourthWord}}">{{myFourthWord}}</a> &#187; </li>
{% endunless %}
{% else %}
<li><a href="/">home</a> &#187; </li>
<li><a href="/{{myFirstWord}}">{{myFirstWord}}</a> &#187; </li>
<li><a href="/{{myFirstWord}}/{{mySecondWord}}">{{mySecondWord}}</a> &#187; </li>
<li><a href="/{{myFirstWord}}/{{mySecondWord}}/{{myThirdWord}}">{{myThirdWord}}</a> &#187; </li>
<li><a href="/{{myFirstWord}}/{{mySecondWord}}/{{myThirdWord}}/{{myFourthWord}}">{{myFourthWord}}</a> &#187; </li>
{% endif %}
</ul>
</div>
<h1>{{ page.title }}</h1>
{{ content }}
</body>
</html>

最佳答案

我对前面给出的答案略有改进。我已删除无序列表并用字符(正斜杠)分隔项目。我为“index.html”和“.html”添加了一个过滤器,因此也支持“mysite.com/path/index.html”和“mysite.com/path/item-name.html”等网址。最后我把标题大写了。这导致如下所示:

首页/路径/元素名称

{% assign crumbs = page.url | remove:'/index.html' | split: '/' %}

<a href="/">Home</a>
{% for crumb in crumbs offset: 1 %}
{% if forloop.last %}
/ {{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}
{% else %}
/ <a href="{% assign crumb_limit = forloop.index | plus: 1 %}{% for crumb in crumbs limit: crumb_limit %}{{ crumb | append: '/' }}{% endfor %}">{{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}</a>
{% endif %}
{% endfor %}

PS。我为这样的片段创建了一个在线资源: jekyllcodex.org/without-plugins

关于breadcrumbs - 在 Jekyll 网站上实现面包屑的好方法有哪些?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9612235/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com