Skip to content

Commit 49626b9

Browse files
george-gcawangmagg
authored andcommitted
Added related posts section (alshedivat#1168)
1 parent e4e8d79 commit 49626b9

11 files changed

+49
-7
lines changed

Gemfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
source 'https://rubygems.org'
22
group :jekyll_plugins do
3+
gem 'classifier-reborn'
34
gem 'jekyll'
45
gem 'jekyll-archives'
56
gem 'jekyll-diagrams'
67
gem 'jekyll-email-protect'
78
gem 'jekyll-feed'
89
gem 'jekyll-imagemagick'
10+
gem 'jekyll-link-attributes'
911
gem 'jekyll-minifier'
1012
gem 'jekyll-paginate-v2'
1113
gem 'jekyll-scholar'
1214
gem 'jekyll-sitemap'
13-
gem 'jekyll-link-attributes'
1415
gem 'jekyll-twitter-plugin'
1516
gem 'jemoji'
1617
gem 'mini_racer'
1718
gem 'unicode_utils'
1819
gem 'webrick'
1920
end
2021
group :other_plugins do
21-
gem 'httparty'
2222
gem 'feedjira'
23+
gem 'httparty'
2324
end

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Images2Symbols (CogSci: <a href="https://images2symbols.github.io/" target="_bla
159159
- [Theming](#theming)
160160
- [Social media previews](#social-media-previews)
161161
- [Atom (RSS-like) Feed](#atom-rss-like-feed)
162+
- [Related posts](#related-posts)
162163
* [Contributing](#contributing)
163164
+ [Core Contributors](#core-contributors)
164165
* [License](#license)
@@ -221,7 +222,7 @@ Assuming you have [Ruby](https://www.ruby-lang.org/en/downloads/) and [Bundler](
221222
$ git clone git@github.com:<your-username>/<your-repo-name>.git
222223
$ cd <your-repo-name>
223224
$ bundle install
224-
$ bundle exec jekyll serve
225+
$ bundle exec jekyll serve --lsi
225226
```
226227

227228
Now, feel free to customize the theme however you like (don't forget to change the name!).
@@ -269,7 +270,7 @@ uses the `master` branch for the source code and deploys the webpage to `gh-page
269270

270271
If you decide to not use GitHub Pages and host your page elsewhere, simply run:
271272
```bash
272-
$ bundle exec jekyll build
273+
$ bundle exec jekyll build --lsi
273274
```
274275
which will (re-)generate the static webpage in the `_site/` folder.
275276
Then simply copy the contents of the `_site/` foder to your hosting server.
@@ -289,7 +290,7 @@ Firstly, from the deployment repo dir, checkout the git branch hosting your publ
289290

290291
Then from the website sources dir (commonly your al-folio fork's clone):
291292
```bash
292-
$ bundle exec jekyll build --destination $HOME/repo/publishing-source
293+
$ bundle exec jekyll build --lsi --destination $HOME/repo/publishing-source
293294
```
294295

295296
This will instruct jekyll to deploy the website under `$HOME/repo/publishing-source`.
@@ -535,6 +536,12 @@ It generates an Atom (RSS-like) feed of your posts, useful for Atom and RSS read
535536
The feed is reachable simply by typing after your homepage `/feed.xml`.
536537
E.g. assuming your website mountpoint is the main folder, you can type `yourusername.github.io/feed.xml`
537538

539+
#### Related posts
540+
By default, there will be a related posts section on the bottom of the blog posts.
541+
These are generated by selecting the `max_related` most recent posts that share at least `min_common_tags` tags with the current post.
542+
If you do not want to display related posts on a specific post, simply add `related_posts: false` to the front matter of the post.
543+
If you want to disable it for all posts, simply set `enabled` to false in the `related_blog_posts` section in `_config.yml`.
544+
538545
## Contributing
539546

540547
Contributions to al-folio are very welcome!

_config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ permalink: /blog/:year/:title/
122122
pagination:
123123
enabled: true
124124

125+
related_blog_posts:
126+
enabled: true
127+
max_related: 5
128+
125129
# Giscus comments (RECOMMENDED)
126130
# Follow instructions on https://giscus.app/ to setup for your repo to fill out
127131
# the information below.

_includes/related_posts.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% assign have_related_posts = false %}
2+
3+
{% for post in site.related_posts | limit: site.related_blog_posts.max_related %}
4+
{% unless have_related_posts %}
5+
{% assign have_related_posts = true %}
6+
<br>
7+
<hr>
8+
<br>
9+
<ul class="list-disc pl-8"></ul>
10+
11+
<!-- Adds related posts to the end of an article -->
12+
<h2 class="text-3xl font-semibold mb-4 mt-12">Enjoy Reading This Article?</h2>
13+
<p class="mb-2">Here are some more articles you might like to read next:</p>
14+
{% endunless %}
15+
16+
<li class="my-2">
17+
<a class="text-pink-700 underline font-semibold hover:text-pink-800" href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>
18+
</li>
19+
{% endfor %}

_layouts/post.html

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ <h1 class="post-title">{{ page.title }}</h1>
4343
{{ content }}
4444
</article>
4545

46+
{%- if site.related_blog_posts.enabled -%}
47+
{%- if page.related_posts == null or page.related_posts -%}
48+
{% include related_posts.html %}
49+
{%- endif %}
50+
{%- endif %}
51+
4652
{%- if site.disqus_shortname and page.disqus_comments -%}
4753
{% include disqus.html %}
4854
{%- endif %}

_posts/2015-10-20-disqus-comments.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ date: 2015-10-20 11:59:00-0400
55
description: an example of a blog post with disqus comments
66
categories: sample-posts external-services
77
disqus_comments: true
8+
related_posts: false
89
---
910
This post shows how to add DISQUS comments.

_posts/2015-10-20-math.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ date: 2015-10-20 11:12:00-0400
55
description: an example of a blog post with some math
66
tags: formatting math
77
categories: sample-posts
8+
related_posts: false
89
---
910
This theme supports rendering beautiful math in inline and display modes using [MathJax 3](https://www.mathjax.org/) engine. You just need to surround your math expression with `$$`, like `$$ E = mc^2 $$`. If you leave it inside a paragraph, it will produce an inline expression, just like $$ E = mc^2 $$.
1011

_posts/2022-02-01-redirect.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ date: 2022-02-01 17:39:00
55
description: you can also redirect to assets like pdf
66
redirect: /assets/pdf/example_pdf.pdf
77
---
8+
9+
Redirecting to another page.

_posts/2022-12-10-giscus-comments.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ date: 2022-12-10 11:59:00-0400
55
description: an example of a blog post with giscus comments
66
categories: sample-posts external-services
77
giscus_comments: true
8+
related_posts: false
89
---
910
This post shows how to add GISCUS comments.

bin/cibuild

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bundle exec jekyll build
1+
bundle exec jekyll build --lsi

bin/deploy

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ git checkout -b $DEPLOY_BRANCH
9393
export JEKYLL_ENV=production
9494

9595
# Build site
96-
bundle exec jekyll build
96+
bundle exec jekyll build --lsi
9797

9898
# Delete and move files
9999
find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name 'CNAME' ! -name '.gitignore' -exec rm -rf {} \;

0 commit comments

Comments
 (0)