04 June 2017

思路:遍历一遍所有的博客,拿出置顶的;再便利一遍所有的博客,拿出非置顶的。

代码

<ul class="list-group">
  for page in site.posts
    if page.keep_top == true
      if page.categories contains category.title
        <li class="list-group-item">
          <p class="keep-in-top-title">置顶</p>
          <a href="page.url">page.title</a>
        </li>
      endif
    endif
  endfor

  for page in site.posts
    if page.keep_top != true
      if page.categories contains category.title
        <li class="list-group-item">
          <a href="page.url">page.title</a>
        </li>
      endif
    endif
  endfor
</ul>

样式

.keep-in-top-title {
    margin: 0 3px 0 0;
    display: inline;
    padding: 0 3px;
    background: #ea0f1f;
    color: #fff;
}

在 MarkDown 文件的顶部,我们就需要一个 keep_top 的标志,类似这样

---
date: 2017-05-01
author: sunx
title: xxx
layout: post
categories:
- note
keep_top: true
---