简体   繁体   English

使用Jekyll创建自定义主页

[英]Create custom home page with Jekyll

I would like to create a custom "home" page using Jekyll's standard theme "Minima". 我想使用Jekyll的标准主题“ Minima”创建一个自定义的“主页”页面。 By default it is set to a list of recent blog posts: 默认情况下,它设置为最近的博客文章列表:

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

This setup is controlled in a file _layouts/home.html . 此设置在_layouts/home.html文件中进行控制。 I have created my custom "home" page using Markdown. 我已经使用Markdown创建了自定义的“主页”页面。 It is saved in my local directory and called "aboutme.md": 它保存在我的本地目录中,名为“ aboutme.md”:

---
layout: page
title: About Me
permalink: /aboutme/
order: 1
---

This is a custom about me page.

I would like to override the default list of recent posts and replace it with my custom "aboutme" page. 我想覆盖最近发布的默认列表,并用我的自定义“ aboutme”页面替换它。 How can I achieve this in an elegant way? 如何以一种优雅的方式实现这一目标? One way is to rewrite the "aboutme.md" in HTML and save it into "home.hml". 一种方法是用HTML重写“ aboutme.md”并将其保存到“ home.hml”中。 However, it is doubling the work. 但是,它使工作加倍。 I'm sure there must be a way to "include" an "aboutme.md" page in "home.html" with a simple Liquid command. 我确信必须有一种方法可以通过简单的Liquid命令在“ home.html”中“包含”“ aboutme.md”页面。 I would also like to have the "About me" page displayed in the site menu. 我还希望站点菜单中显示“关于我”页面。

You should rename your 'aboutme.md' file to 'index.md', remove the permalink statement and save it in the root of your website directory (and optionally rename the old index.md to blog.md). 您应该将“ aboutme.md”文件重命名为“ index.md”,删除永久链接语句,并将其保存在网站目录的根目录中(还可以将旧的index.md重命名为blog.md)。

Like this: (index.md) 像这样:(index.md)

---
layout: page
title: About Me
order: 1
---

This is now the homepage.

To customize home page, locate where your minima gem files are located in your system and copy _layouts/home.html to your Jekyll instance maintaining the directory structure . 要自定义首页,请找到最小的gem文件在系统中的位置,然后将_layouts / home.html复制到维护目录结构的Jekyll实例中。

/_layouts/home.html

There you can edit it as you wish, replacing the blog posts list with a link to an about me page or including an about me section. 在这里,您可以根据需要对其进行编辑,将博客帖子列表替换为指向“关于我”页面或包含“关于我”部分的链接。

  • update 更新

To include the contents of the "about me" page as a section of the home page, you can add the following code in your /index.md : 要将“关于我”页面的内容作为主页的一部分包括在内,可以在/index.md添加以下代码:

{% assign about = site.pages | where: 'name','about.md' %}
{{about}}

It looks for the filename called about.md and include its contents where you put that. 它查找名为about.md的文件名,并在其中放置其内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM