jekyll-stickyposts 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -5
- data/lib/jekyll/stickyposts.rb +50 -44
- data/lib/jekyll/stickyposts/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6eb63684ec605e9b63c8bf7cd3352f92999034d
|
4
|
+
data.tar.gz: 2b975a7ea1bbf9a458f78a660e1744bb895e28e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24d210065cec2d9613c59e85a67cc93c4f1b0c1189673df9110d0a514e053a37f9b4a8690ee3b97d9fd197003ec31556adae27d319fcd8c0e138e3cb4c4a7c8e
|
7
|
+
data.tar.gz: 337c5e50321e0627c562e819ff4a857ed24b0b9081c0951846ca4605724230abacee515ffcdc235a84c02303629ef0bf0a7c7e705bcacb58cf3668b527160d4e
|
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# Jekyll::StickyPosts
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/jekyll-stickyposts)
|
4
4
|
|
5
5
|
*StickyPosts* is a plugin for [Jekyll](https://jekyllrb.com/) that sticks/pins posts marked `sticky: true` to the top, i.e. it moves them before all others. Optionally, the posts could also appear where they normally would.
|
6
6
|
|
7
7
|
### Why do this?
|
8
8
|
|
9
9
|
1. You want to keep important announcements, etc. at the top of your home page
|
10
|
+
1. You want descriptive entries to appear at the top of your collections
|
10
11
|
|
11
12
|
## Installation
|
12
13
|
|
@@ -38,6 +39,17 @@ stickyposts:
|
|
38
39
|
sort: "blah" # Optional sort field; default: "date", use "none" to avoid sorting
|
39
40
|
reverse: true # Ascending order, default: false
|
40
41
|
retain: true # Also show sticky posts in their original positions; default: false
|
42
|
+
|
43
|
+
#collection: articles # The collection to "stickify"; default "posts"
|
44
|
+
|
45
|
+
# Or multiple collections:
|
46
|
+
#collections:
|
47
|
+
# - posts
|
48
|
+
# - articles
|
49
|
+
|
50
|
+
# Same thing:
|
51
|
+
#collections: ["posts", "articles"]
|
52
|
+
|
41
53
|
```
|
42
54
|
|
43
55
|
> Note: if you set `sort` to `"none"` and don't sort as described in the next section, Jekyll will re-sort the documents by date. This may move the sticky posts out of position.
|
@@ -59,14 +71,14 @@ If you're using a paginator that allows sorting on fields, e.g. [jekyll-paginate
|
|
59
71
|
pagination:
|
60
72
|
# ...
|
61
73
|
sort_field: "stickiness"
|
62
|
-
|
74
|
+
sort_reverse: false
|
63
75
|
# ...
|
64
76
|
|
65
77
|
# ...etc...
|
66
78
|
|
67
79
|
stickyposts:
|
68
|
-
|
69
|
-
#reverse: true #
|
80
|
+
sort: "date" # or your original pagination sort_field
|
81
|
+
#reverse: true # ditto for the sort_reverse
|
70
82
|
# ...etc...
|
71
83
|
```
|
72
84
|
|
@@ -77,7 +89,7 @@ No changes will be required in your pagination setup:
|
|
77
89
|
...etc...
|
78
90
|
{% endfor %}
|
79
91
|
```
|
80
|
-
##
|
92
|
+
## Miscellany
|
81
93
|
|
82
94
|
You may want to mark sticky posts with e.g. a pin from [FontAwesome](http://fontawesome.io/):
|
83
95
|
|
@@ -87,6 +99,25 @@ You may want to mark sticky posts with e.g. a pin from [FontAwesome](http://font
|
|
87
99
|
{% endif %}
|
88
100
|
```
|
89
101
|
|
102
|
+
Or, if you want to put a header/descriptive post at the top of your collections:
|
103
|
+
|
104
|
+
```html
|
105
|
+
{% if post.sticky %}
|
106
|
+
# Formatting for the header
|
107
|
+
{% else %}
|
108
|
+
# Formatting for normal entries
|
109
|
+
{% endif %}
|
110
|
+
```
|
111
|
+
|
112
|
+
Or similarly:
|
113
|
+
|
114
|
+
```html
|
115
|
+
{% unless post.sticky %}
|
116
|
+
# Meta information for the entry
|
117
|
+
{% endunless %}
|
118
|
+
# The rest of the entry description, e.g. excerpt
|
119
|
+
```
|
120
|
+
|
90
121
|
## Demo
|
91
122
|
|
92
123
|
See the [author's blog](https://ibrado.org/) for a (possible) demo.
|
@@ -113,3 +144,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
113
144
|
|
114
145
|
## Code of Conduct
|
115
146
|
Everyone interacting in the Jekyll::StickyPosts project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/jekyll-stickyposts/blob/master/CODE_OF_CONDUCT.md).
|
147
|
+
|
148
|
+
## Also by the author
|
149
|
+
|
150
|
+
[Jekyll Tweetsert Plugin](https://github.com/ibrado/jekyll-tweetsert) - Turn tweets into Jekyll documents. Multiple timelines, filters, hashtags, automatic category/tags, and more!
|
data/lib/jekyll/stickyposts.rb
CHANGED
@@ -29,64 +29,70 @@ module Jekyll
|
|
29
29
|
return if !(config["enabled"].nil? || config["enabled"])
|
30
30
|
|
31
31
|
debug = config["debug"]
|
32
|
-
StickyPosts::debug_state debug
|
33
|
-
|
34
|
-
collection = config["collection"] || "posts";
|
32
|
+
StickyPosts::debug_state debug
|
35
33
|
|
36
34
|
sort_field = config["sort"] || 'date'
|
37
35
|
sort_reverse = config["reverse"]
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
collections = [ config['collection'], config["collections"] ].flatten.compact;
|
38
|
+
collections = [ "posts" ] if collections.empty?
|
39
|
+
|
40
|
+
if config["sort"]
|
42
41
|
StickyPosts::debug "Sorting by #{sort_field}, reverse: #{sort_reverse ? "true" : "false"}"
|
43
|
-
|
44
|
-
a = docA.data[sort_field]
|
45
|
-
b = docB.data[sort_field]
|
46
|
-
|
47
|
-
if a.nil? && !b.nil?
|
48
|
-
-1
|
49
|
-
elsif !a.nil? && b.nil?
|
50
|
-
1
|
51
|
-
end
|
42
|
+
end
|
52
43
|
|
53
|
-
|
54
|
-
|
55
|
-
end
|
44
|
+
collections.each do |collection|
|
45
|
+
sorted = site.collections[collection].docs
|
56
46
|
|
57
|
-
|
58
|
-
|
47
|
+
unless config["sort"] == "none"
|
48
|
+
sorted.sort! { |docB, docA|
|
49
|
+
a = docA.data[sort_field]
|
50
|
+
b = docB.data[sort_field]
|
59
51
|
|
60
|
-
|
61
|
-
|
52
|
+
if a.nil? && !b.nil?
|
53
|
+
-1
|
54
|
+
elsif !a.nil? && b.nil?
|
55
|
+
1
|
56
|
+
end
|
62
57
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
else
|
72
|
-
copy = Jekyll::Document.new(post.path, { :site => site, :collection => site.posts })
|
73
|
-
copy.merge_data!(post.data)
|
74
|
-
sticky << copy
|
75
|
-
end
|
76
|
-
remove
|
58
|
+
if a.respond_to?('to_datetime') && b.respond_to?('to_datetime')
|
59
|
+
a.to_datetime <=> b.to_datetime
|
60
|
+
end
|
61
|
+
|
62
|
+
a <=> b
|
63
|
+
}
|
64
|
+
|
65
|
+
sorted.reverse! if sort_reverse
|
77
66
|
end
|
78
|
-
end
|
79
67
|
|
80
|
-
|
68
|
+
remove = config["retain"].nil? || !config["retain"]
|
69
|
+
|
70
|
+
sticky = []
|
71
|
+
sorted.delete_if do |doc|
|
72
|
+
if doc.data['sticky']
|
73
|
+
StickyPosts::debug "\"#{doc.data['title']}\" is sticky, #{remove ? "removing" : "retaining"} copy"
|
74
|
+
if remove
|
75
|
+
sticky << doc
|
76
|
+
else
|
77
|
+
copy = Jekyll::Document.new(doc.path, { :site => site,
|
78
|
+
:collection => site.collections[collection]})
|
79
|
+
copy.merge_data!(doc.data)
|
80
|
+
sticky << copy
|
81
|
+
end
|
82
|
+
remove
|
83
|
+
end
|
84
|
+
end
|
81
85
|
|
82
|
-
|
83
|
-
sorted.each do |post|
|
84
|
-
post.data["stickiness"] = order
|
85
|
-
order += 1
|
86
|
-
end
|
86
|
+
sorted.unshift(*sticky)
|
87
87
|
|
88
|
-
|
88
|
+
order = 0;
|
89
|
+
sorted.each do |doc|
|
90
|
+
doc.data["stickiness"] = order
|
91
|
+
order += 1
|
92
|
+
end
|
89
93
|
|
94
|
+
StickyPosts::info "[#{collection}] #{sticky.length} post(s) pinned"
|
95
|
+
end
|
90
96
|
end
|
91
97
|
end
|
92
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-stickyposts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Ibrado
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|