Skip to content

Commit

Permalink
Added related posts section (alshedivat#1168)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-gca authored and mhnazeri committed Sep 17, 2023
1 parent 1334d54 commit 763932b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
source 'https://rubygems.org'
group :jekyll_plugins do
gem 'classifier-reborn'
gem 'jekyll'
gem 'jekyll-archives'
gem 'jekyll-diagrams'
gem 'jekyll-email-protect'
gem 'jekyll-feed'
gem 'jekyll-imagemagick'
gem 'jekyll-link-attributes'
gem 'jekyll-minifier'
gem 'jekyll-paginate-v2'
gem 'jekyll-scholar'
gem 'jekyll-sitemap'
gem 'jekyll-link-attributes'
gem 'jekyll-twitter-plugin'
gem 'jemoji'
gem 'mini_racer'
Expand All @@ -19,6 +20,6 @@ group :jekyll_plugins do
gem 'jekyll-target-blank'
end
group :other_plugins do
gem 'httparty'
gem 'feedjira'
gem 'httparty'
end
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Images2Symbols (CogSci: <a href="https://images2symbols.github.io/" target="_bla
- [Theming](#theming)
- [Social media previews](#social-media-previews)
- [Atom (RSS-like) Feed](#atom-rss-like-feed)
- [Related posts](#related-posts)
* [Contributing](#contributing)
+ [Core Contributors](#core-contributors)
* [License](#license)
Expand Down Expand Up @@ -221,7 +222,7 @@ Assuming you have [Ruby](https://www.ruby-lang.org/en/downloads/) and [Bundler](
$ git clone git@github.com:<your-username>/<your-repo-name>.git
$ cd <your-repo-name>
$ bundle install
$ bundle exec jekyll serve
$ bundle exec jekyll serve --lsi
```

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

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

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

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

#### Related posts
By default, there will be a related posts section on the bottom of the blog posts.
These are generated by selecting the `max_related` most recent posts that share at least `min_common_tags` tags with the current post.
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.
If you want to disable it for all posts, simply set `enabled` to false in the `related_blog_posts` section in `_config.yml`.

## Contributing

Contributions to al-folio are very welcome!
Expand Down
24 changes: 22 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,28 @@ permalink: /blog/:year/:title/
pagination:
enabled: true

# Comments
disqus_shortname: mhnazeri # put your disqus shortname
related_blog_posts:
enabled: true
max_related: 5

# Giscus comments (RECOMMENDED)
# Follow instructions on https://giscus.app/ to setup for your repo to fill out
# the information below.
giscus:
repo: alshedivat/al-folio # <your-github-user-name>/<your-github-repo-name>
repo_id: MDEwOlJlcG9zaXRvcnk2MDAyNDM2NQ==
category: Comments # name of the category under which discussions will be created
category_id: DIC_kwDOA5PmLc4CTBt6
mapping: title # identify discussions by post title
strict: 1 # use strict identification mode
reactions_enabled: 1 # enable (1) or disable (0) emoji reactions
input_position: bottom # whether to display input form below (bottom) or above (top) the comments
theme: preferred_color_scheme # name of the color scheme (preferred works well with al-folio light/dark mode)
emit_metadata: 0
lang: en

# Disqus comments (DEPRECATED)
disqus_shortname: al-folio # put your disqus shortname
# https://help.disqus.com/en/articles/1717111-what-s-a-shortname

# External sources.
Expand Down
19 changes: 19 additions & 0 deletions _includes/related_posts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% assign have_related_posts = false %}

{% for post in site.related_posts | limit: site.related_blog_posts.max_related %}
{% unless have_related_posts %}
{% assign have_related_posts = true %}
<br>
<hr>
<br>
<ul class="list-disc pl-8"></ul>

<!-- Adds related posts to the end of an article -->
<h2 class="text-3xl font-semibold mb-4 mt-12">Enjoy Reading This Article?</h2>
<p class="mb-2">Here are some more articles you might like to read next:</p>
{% endunless %}

<li class="my-2">
<a class="text-pink-700 underline font-semibold hover:text-pink-800" href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>
</li>
{% endfor %}
6 changes: 6 additions & 0 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ <h1 class="post-title">{{ page.title }}</h1>
{{ content }}
</article>

{%- if site.related_blog_posts.enabled -%}
{%- if page.related_posts == null or page.related_posts -%}
{% include related_posts.html %}
{%- endif %}
{%- endif %}

{%- if site.disqus_shortname and page.disqus_comments -%}
{% include disqus.html %}
{%- endif %}
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion bin/cibuild
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bundle exec jekyll build
bundle exec jekyll build --lsi
2 changes: 1 addition & 1 deletion bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ git checkout -b $DEPLOY_BRANCH
export JEKYLL_ENV=production

# Build site
bundle exec jekyll build
bundle exec jekyll build --lsi

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

0 comments on commit 763932b

Please sign in to comment.