jekyll-archives

repository·master·Indexed 19 days ago

https://github.com/jekyll/jekyll-archives

A Jekyll plugin that automatically generates post archive pages organized by dates, tags, and categories. It allows for custom permalink structures, type-specific layouts, and provides specialized Liquid attributes (such as page.posts, page.date, and page.type) to dynamically render archive content.

Tokens
2.6K
Snippets
13
Records
15
Agent score
62%

What's inside jekyll-archives

  1. Use archive layout attributes in Liquid

    master

    When creating archive layouts, jekyll-archives provides special attributes via the page object to represent information about the specific archive being generated. These attributes allow you to dynamically display titles, dates, and the list of posts associated with the archive.

    Available Attributes

    AttributeTypeDescription
    page.titleString / nilContains the name of the tag or category. Returns nil for date-based archives (year, month, day).
    page.dateDate / nilA Date object for date-based archives. For year archives, ignore month/day; for month archives, ignore day. Returns nil for tag/category archives.
    page.postsArrayAn array of Post objects matching the archive criteria.
    page.typeStringThe type of archive being generated. Values: tag, category, year, month, or day.

    Note: To handle different archive types cleanly, it is recommended to use type-specific layouts.

  2. Configure jekyll-archives in _config.yml

    master

    All configuration for the jekyll-archives plugin must be placed under the jekyll-archives key in your site's _config.yml file.

    jekyll-archives:
      enabled: []
      layout: archive
      permalinks:
        year: '/:year/'
        month: '/:year/:month/'
        day: '/:year/:month/:day/'
        tag: '/tag/:name/'
        category: '/category/:name/'
  3. Enable specific archive types

    master

    Use the enabled key to specify which archives should be generated. You can either set it to the string 'all' to enable every archive type, or provide an array containing a combination of year, month, day, categories, and tags.

    enabled: all
    
    # Or specify an array
    enabled:
      - categories
    
    enabled:
      - year
      - month
      - tags
  4. Configure archive permalinks

    master

    The permalinks key allows you to define the URL structure for each archive type. The format follows standard Jekyll permalink syntax but uses specific variables:

    • :year (for year archives)
    • :year and :month (for month archives)
    • :year, :month, and :day (for day archives)
    • :name (for category and tag archives)

    Note: You must include trailing slashes (e.g., '/path/') to ensure the archive is generated as an index.html file within a directory.

    permalinks:
      year: '/archives/year/:year/'
      month: '/archives/month/:year-:month/'
      tag: '/archives/tag/:name/'
  5. Set archive layouts

    master

    You can control which Jekyll layouts are used to render your archives using two different keys:

    1. layout: Sets a global default layout for all archives. If a type-specific layout is not defined, the plugin falls back to this value.
    2. layouts: A map that allows you to assign specific layouts to specific archive types (year, month, day, category, or tag).
    # Set a global default
    layout: archive
    
    # Map specific types to specific layouts
    layouts:
      year: year-archive
      month: month-archive
      day: day-archive
      category: category-archive
      tag: tag-archive
  6. Configure jekyll-archives

    master

    Archive generation behavior is controlled via the jekyll-archives key in your _config.yml file. This key allows you to define how archives are generated for different taxonomies (like dates, tags, or categories).

    # _config.yml
    jekyll-archives:
      # Configuration options go here
  7. Create a Month archive layout

    master

    For month archives, use page.date to display the month and year. When processing the page.date object, ignore the day component.

    <h1>Archive of posts from {{ page.date | date: "%B %Y" }}</h1>
    
    <ul class="posts">
    {% for post in page.posts %}
      <li>
        <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
        <a class="post-link" href="{{ post.url | relative_url }}">{{ post.title }}</a>
      </li>
    {% endfor %}
    </ul>
  8. Create a Tag or Category archive layout

    master

    For tag and category archives, use page.title to display the name of the tag/category and page.type to identify the archive type. Iterate over page.posts to list the posts.

    <h1>Archive of posts with {{ page.type }} '{{ page.title }}'</h1>
    <ul class="posts">
      {% for post in page.posts %}
        <li>
          <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
          <a class="post-link" href="{{ post.url | relative_url }}">{{ post.title }}</a>
        </li>
      {% endfor %}
    </ul>
  9. Create a Day archive layout

    master

    For day archives, use page.date to display the full date (Month, Day, Year).

    <h1>Archive of posts from {{ page.date | date: "%B %-d, %Y" }}</h1>
    
    <ul class="posts">
    {% for post in page.posts %}
      <li>
        <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
        <a class="post-link" href="{{ post.url | relative_url }}">{{ post.title }}</a>
      </li>
    {% endfor %}
    </ul>
  10. Create a Year archive layout

    master

    For year archives, use page.date to display the year. When processing the page.date object, ignore the month and day components.

    <h1>Archive of posts from {{ page.date | date: "%Y" }}</h1>
    
    <ul class="posts">
    {% for post in page.posts %}
      <li>
        <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
        <a class="post-link" href="{{ post.url | relative_url }}">{{ post.title }}</a>
      </li>
    {% endfor %}
    </ul>