[英]Create custom home page with Jekyll
我想使用Jekyll的标准主题“ Minima”创建一个自定义的“主页”页面。 默认情况下,它设置为最近的博客文章列表:
---
layout: default
---
<div class="home">
<h1 class="page-heading">Posts</h1>
{{ content }}
<ul class="post-list">
{% for post in site.posts %}
<li>
<span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>
<h2>
<a class="post-link" href="{{ post.url | relative_url }}">{{ post.title | escape }}</a>
</h2>
</li>
{% endfor %}
</ul>
<p class="rss-subscribe">subscribe <a href="{{ "/feed.xml" | relative_url }}">via RSS</a></p>
</div>
此设置在_layouts/home.html
文件中进行控制。 我已经使用Markdown创建了自定义的“主页”页面。 它保存在我的本地目录中,名为“ aboutme.md”:
---
layout: page
title: About Me
permalink: /aboutme/
order: 1
---
This is a custom about me page.
我想覆盖最近发布的默认列表,并用我的自定义“ aboutme”页面替换它。 如何以一种优雅的方式实现这一目标? 一种方法是用HTML重写“ aboutme.md”并将其保存到“ home.hml”中。 但是,它使工作加倍。 我确信必须有一种方法可以通过简单的Liquid命令在“ home.html”中“包含”“ aboutme.md”页面。 我还希望站点菜单中显示“关于我”页面。
您应该将“ aboutme.md”文件重命名为“ index.md”,删除永久链接语句,并将其保存在网站目录的根目录中(还可以将旧的index.md重命名为blog.md)。
像这样:(index.md)
---
layout: page
title: About Me
order: 1
---
This is now the homepage.
要自定义首页,请找到最小的gem文件在系统中的位置,然后将_layouts / home.html复制到维护目录结构的Jekyll实例中。
/_layouts/home.html
在这里,您可以根据需要对其进行编辑,将博客帖子列表替换为指向“关于我”页面或包含“关于我”部分的链接。
要将“关于我”页面的内容作为主页的一部分包括在内,可以在/index.md
添加以下代码:
{% assign about = site.pages | where: 'name','about.md' %}
{{about}}
它查找名为about.md
的文件名,并在其中放置其内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.