Skip to content

Commit a1a5d79

Browse files
committed
Super feature: Pinned posts.
1 parent ad7a3ed commit a1a5d79

File tree

7 files changed

+75
-9
lines changed

7 files changed

+75
-9
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ A minimal, sidebar, responsive web design Jekyll theme, focusing on text present
2222

2323
## Features
2424

25+
* Pinned Posts
2526
* Configurable theme mode
26-
* Two-level Categories
27+
* Double-level Categories
2728
* Last modified date for posts
2829
* Table of Contents
2930
* Automatically recommend related posts

Diff for: _layouts/home.html

+54-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,59 @@
77
# MIT Licensed
88
---
99

10+
11+
{% assign pinned = site.posts | where_exp: "item", "item.pin == true" %}
12+
13+
{% assign default = site.posts | where_exp: "item", "item.pin == nil " %}
14+
15+
{% assign posts = "" | split: "" %}
16+
17+
<!-- Get pinned posts -->
18+
19+
{% assign offset = paginator.page | minus: 1 | times: paginator.per_page %}
20+
21+
{% assign pinned_num = pinned.size | minus: offset %}
22+
23+
{% if pinned_num > 0 %}
24+
{% for i in (offset..pinned.size) limit: pinned_num %}
25+
{% assign posts = posts | push: pinned[i] %}
26+
{% endfor %}
27+
{% else %}
28+
{% assign pinned_num = 0 %}
29+
{% endif %}
30+
31+
32+
<!-- Get defualt posts -->
33+
34+
{% assign default_beg = offset | minus: pinned.size %}
35+
36+
{% if default_beg < 0 %}
37+
{% assign default_beg = 0 %}
38+
{% endif %}
39+
40+
{% assign default_num = paginator.posts | size | minus: pinned_num %}
41+
42+
{% assign default_end = default_beg | plus: default_num | minus: 1 %}
43+
44+
{% if default_num > 0 %}
45+
{% for i in (default_beg..default_end) %}
46+
{% assign posts = posts | push: default[i] %}
47+
{% endfor %}
48+
{% endif %}
49+
50+
1051
<div id="post-list">
11-
{% for post in paginator.posts %}
52+
53+
{% for post in posts %}
54+
1255
<div class="post-preview">
13-
<h1>
14-
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
15-
</h1>
56+
<div class="d-flex justify-content-between align-items-center pr-2">
57+
<h1><a href="{{ post.url | relative_url }}">{{ post.title }}</a></h1>
58+
{% if post.pin %}
59+
<i class="fas fa-thumbtack fa-fw fa-sm text-muted pinned" data-toggle="tooltip" data-placement="top"
60+
title="Pinned"></i>
61+
{% endif %}
62+
</div>
1663
<div class="post-content">
1764
<p>
1865
{% assign _content = post.content %}
@@ -38,7 +85,9 @@ <h1>
3885
{% endif %}
3986
</div>
4087
</div> <!-- .post-review -->
41-
{% endfor %}
88+
89+
{% endfor %}
90+
4291
</div> <!-- #post-list -->
4392

4493
{% if paginator.total_pages > 0 %}

Diff for: _posts/2019-08-08-write-a-new-post.md

+11
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ math: true
124124
```
125125

126126

127+
## Pinned Posts
128+
129+
You can pin one or more posts to the top of the home page, and the fixed posts are sorted in reverse order according to their release date. Enable by:
130+
131+
```yaml
132+
---
133+
pin: true
134+
---
135+
```
136+
137+
127138
## Code Block
128139

129140
Markdown symbols <code class="highlighter-rouge">```</code> can easily create a code block as following examples.

Diff for: _posts/2019-08-09-getting-started.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ author: Cotes Chung
44
date: 2019-08-09 20:55:00 +0800
55
categories: [Blogging, Tutorial]
66
tags: [getting started]
7+
pin: true
78
---
89

910
## Prerequisites

Diff for: assets/css/home.scss

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
padding-top: 1.5rem;
3030
padding-bottom: 1rem;
3131
border-bottom: 1px solid var(--main-border-color);
32-
>h1 {
32+
h1 {
3333
font-size: 1.4rem;
3434
margin: 0;
3535
}
@@ -49,6 +49,9 @@
4949
-webkit-box-orient: vertical;
5050
}
5151
}
52+
.pinned {
53+
transform: rotate(45deg);
54+
}
5255
}
5356

5457
.page-item {

Diff for: assets/js/_utils/pageviews.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function displayPageviews(data) {
6969

7070
if ($("#post-list").length > 0) { /* the Home page */
7171
$(".post-preview").each(function() {
72-
var path = $(this).children("h1").children("a").attr("href");
72+
var path = $(this).children("div").children("h1").children("a").attr("href");
7373
tacklePV(rows, path, $(this).find('.pageviews'), hasInit);
7474
});
7575

Diff for: docs/README_zh-CN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
## 功能预览
2626

27-
* 自动暗夜模式
27+
* 文章置顶
28+
* 可配置的全局主题颜色
2829
* 文章最后修改日期
2930
* 文章目录
3031
* 自动推荐相关文章

0 commit comments

Comments
 (0)