[jekyll] 03 設定首頁的內容

以下是設定 Jekyll 首頁內容的步驟:

  1. **修改 _config.yml**:
    確保您的 _config.yml 中有以下設置:

    1
    2
    paginate: 5
    paginate_path: "/page:num/"
  2. 創建首頁模板
    _layouts 目錄中創建一個 home.html 文件,並添加以下內容:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    ---
    layout: default
    ---

    <div class="home">
    <h1 class="page-heading">{{ page.title | escape }}</h1>
    <ul class="post-list">
    {% for post in paginator.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>
    <div class="pagination">
    {% if paginator.previous_page %}
    <a class="pagination-item older" href="{{ paginator.previous_page_path | relative_url }}">&larr; Older</a>
    {% endif %}
    {% if paginator.next_page %}
    <a class="pagination-item newer" href="{{ paginator.next_page_path | relative_url }}">Newer &rarr;</a>
    {% endif %}
    </div>
    </div>
  3. 更新首頁文件
    確保您的 index.md 文件中有以下內容:

    1
    2
    3
    4
    5
    ---
    layout: home
    title: "首頁"
    permalink: /
    ---

完成以上步驟後,您的 Jekyll 首頁就會顯示最新的文章列表!


[jekyll] 03 設定首頁的內容
https://terryyaowork.github.io/blog/20240623/2077178930/
作者
Terry Yao
發布於
2024年6月23日
許可協議