【问题标题】:Dynamic title AND content in JekyllJekyll 中的动态标题和内容
【发布时间】:2015-11-22 23:37:31
【问题描述】:

我有一个结构有点像这样的页面

---
layout: contents
title: contents
description: Contents of the posts.
permalink: contents/
---


      <ul class="posts">
        {% for post in site.posts %}
            {% if post.categories != "tips" %}
          <h2><a class="post-heading" href="{{ post.url }}">{{ post.title }}</a></h2>
          <p> {{ post.description }} </p>
          <p class="date">{{ post.date | date_to_string }}</p>
          <hr class="hr-color"></hr>
          {% endif %}
        {% endfor %}
      </ul >

目前该页面的URL是根据permalinks(BASE_URL/contents)设置的。我希望当用户单击上一页中的选项(Android、Java、Web 是选项)时,我会将此页面的 URL 设为 BASE_URL/androidBASE_URL/Java 并显示该类别的内容。

这可以使用 jekyll 吗?

【问题讨论】:

    标签: web jekyll liquid github-pages static-site


    【解决方案1】:

    两种解决方案:

    1 - 使用插件

    您可以使用this category archive generator

    2 - 使用手工制作的页面

    如果您不能使用插件(gh-pages),您可以为每个类别创建一个页面,如下所示:

    android.html

    ---
    layout: category
    title: Android
    permalink: android/
    ---
    

    _layouts/category.hmtl

    ---
    layout: default
    ---
    
    <ul class="posts">
      {% for post in site.posts %}
        {% if post.categories contains page.title %}
          <h2><a class="post-heading" href="{{ post.url }}">{{ post.title }}</a></h2>
          <p> {{ post.description }} </p>
          <p class="date">{{ post.date | date_to_string }}</p>
          <hr class="hr-color"></hr>
        {% endif %}
      {% endfor %}
    </ul >
    

    【讨论】:

    • 第 2 点实际上并不是一个好的解决方案。将研究第 1 点。我现在正在投票。如果可行,将接受。
    猜你喜欢
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多