StickyPosts is a plugin for Jekyll 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.
- You want to keep important announcements, etc. at the top of your home page
- You want descriptive entries to appear at the top of your collections
v1.2.2 Allow inclusion in _config.yml
plugins
v1.2.1 Fix sorting
v1.2.0 Add reverse_sticky
option
v1.1.0 Support multiple collections
Add the gem to your application's Gemfile:
group :jekyll_plugins do
# other plugins here
gem 'jekyll-stickyposts'
end
And then execute:
$ bundle
Or install it yourself:
$ gem install jekyll-stickyposts
No configuration is required to run StickyPosts. If you want to tweak its behavior, you may set the following options in _config.yml
:
stickyposts:
#enabled: false # Enable StickyPosts; default: true
debug: true # Show additional info; default: false
sort: "blah" # Optional sort field; default: "date", use "none" to avoid sorting
reverse: true # Ascending order, default: false
retain: true # Also show sticky posts in their original positions; default: false
reverse_sticky: true # Reverse the order of the sticky posts, e.g. oldest first; default: false
#collection: articles # The collection to "stickify"; default "posts"
# Or multiple collections:
#collections:
# - posts
# - articles
# Same thing:
#collections: ["posts", "articles"]
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 will likely move the sticky posts out of position.
Just add a sticky: true
entry to your front matter:
---
title: Test
date: 2017-12-15 22:33:44
sticky: true
---
If you're not using a paginator at all, use something like:
{% assign sorted = site.posts | sort: "stickiness" %}
{% for post in sorted %}
...etc...
{% endfor %}
If you're using the original jekyll-paginate:
{% assign sorted = paginator.posts | sort: "stickiness" %}
{% for post in sorted %}
...etc...
{% endfor %}
If you're using a paginator that allows sorting on fields, e.g. jekyll-paginate-v2, you need to edit your _config.yml
a bit:
pagination:
# ...
sort_field: "stickiness"
sort_reverse: false
# ...
# ...etc...
stickyposts:
sort: "date" # or your original pagination sort_field
#reverse: true # ditto for the sort_reverse
# ...etc...
No changes will be required in your pagination setup:
{% for post in paginator.posts %}
...etc...
{% endfor %}
You may want to mark sticky posts with e.g. a pin from FontAwesome:
{% if post.sticky %}
<span class="sticky"><i class="fa fa-thumb-tack" aria-hidden="true"></i></span>
{% endif %}
Or, if you want to put a header/descriptive post at the top of your collections:
{% if post.sticky %}
# Formatting for the header
{% else %}
# Formatting for normal entries
{% endif %}
Or similarly:
{% unless post.sticky %}
# Meta information for the entry
{% endunless %}
# The rest of the entry description, e.g. excerpt
See the author's blog for a (possible) demo.
- Fork this project: https://github.com/ibrado/jekyll-stickyposts/fork
- Clone it (
git clone git:https://github.com/your_user_name/jekyll-stickyposts.git
) cd jekyll-stickyposts
- Create a new branch (e.g.
git checkout -b my-bug-fix
) - Make your changes
- Commit your changes (
git commit -m "Bug fix"
) - Build it (
gem build jekyll-stickyposts.gemspec
) - Install and test it (
gem install ./jekyll-stickyposts-*.gem
) - Repeat from step 5 as necessary
- Push the branch (
git push -u origin my-bug-fix
) - Create a Pull Request, making sure to select the proper branch, e.g.
my-bug-fix
(via https://github.com/*your_user_name*/jekyll-stickyposts)
Bug reports and pull requests are welcome on GitHub at https://github.com/ibrado/jekyll-stickyposts. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Jekyll::StickyPosts project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Jekyll Tweetsert Plugin - Turn tweets into Jekyll posts. Multiple timelines, filters, hashtags, automatic category/tags, and more!
Jekyll::Paginate::Content - Split your Jekyll pages, posts, etc. into multiple pages automatically. Single-page view, pager, SEO support, self-adjusting links, multipage-aware Table Of Contents.
Jekyll::ViewSource - Generate pretty or plain HTML and/or Markdown source code pages.