Skip to content

Commit

Permalink
Implemented latest posts on about page (alshedivat#1307)
Browse files Browse the repository at this point in the history
Adresses alshedivat#340

---------

Signed-off-by: George Araújo <george.gcac@gmail.com>
  • Loading branch information
george-gca committed Apr 8, 2023
1 parent 7e07978 commit 3a91ce4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
11 changes: 9 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,15 @@ collections:
output: true
permalink: /projects/:path/

news_scrollable: true # adds a vertical scroll bar if there are more than 3 news items
news_limit: 5 # leave blank to include all the news in the `_news` folder
news:
enabled: true
scrollable: true # adds a vertical scroll bar if there are more than 3 news items
limit: 5 # leave blank to include all the news in the `_news` folder

latest_posts:
enabled: true
scrollable: true # adds a vertical scroll bar if there are more than 3 new posts items
limit: 3 # leave blank to include all the blog posts

# -----------------------------------------------------------------------------
# Jekyll settings
Expand Down
26 changes: 26 additions & 0 deletions _includes/latest_posts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

<div class="news">
{% if site.latest_posts != blank -%}
{%- assign latest_posts_size = site.posts | size -%}
<div class="table-responsive" {% if site.latest_posts.scrollable and latest_posts_size > 3 %}style="max-height: 10vw"{% endif %}>
<table class="table table-sm table-borderless">
{%- assign latest_posts = site.posts -%}
{% if site.latest_posts.limit %}
{% assign latest_posts_limit = site.latest_posts.limit %}
{% else %}
{% assign latest_posts_limit = latest_posts_size %}
{% endif %}
{% for item in latest_posts limit: latest_posts_limit %}
<tr>
<th scope="row">{{ item.date | date: "%b %-d, %Y" }}</th>
<td>
<a class="news-title" href="{{ item.url | relative_url }}">{{ item.title }}</a>
</td>
</tr>
{%- endfor %}
</table>
</div>
{%- else -%}
<p>No posts so far...</p>
{%- endif %}
</div>
24 changes: 12 additions & 12 deletions _includes/news.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@

<div class="news">
{% if site.news != blank -%}
{% if site.news != blank -%}
{%- assign news_size = site.news | size -%}
<div class="table-responsive" {% if site.news_scrollable and news_size > 3 %}style="max-height: 10vw"{% endif %}>
<div class="table-responsive" {% if site.news.scrollable and news_size > 3 %}style="max-height: 10vw"{% endif %}>
<table class="table table-sm table-borderless">
{%- assign news = site.news | reverse -%}
{% if site.news_limit %}
{% assign news_limit = site.news_limit %}
{% if site.news.limit %}
{% assign news_limit = site.news.limit %}
{% else %}
{% assign news_limit = news_size %}
{% endif %}
{% for item in news limit: news_limit %}
{% for item in news limit: news_limit %}
<tr>
<th scope="row">{{ item.date | date: "%b %-d, %Y" }}</th>
<td>
{% if item.inline -%}
{% if item.inline -%}
{{ item.content | remove: '<p>' | remove: '</p>' | emojify }}
{%- else -%}
{%- else -%}
<a class="news-title" href="{{ item.url | relative_url }}">{{ item.title }}</a>
{%- endif %}
{%- endif %}
</td>
</tr>
{%- endfor %}
{%- endfor %}
</table>
</div>
{%- else -%}
{%- else -%}
<p>No news so far...</p>
{%- endif %}
{%- endif %}
</div>
12 changes: 9 additions & 3 deletions _layouts/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ <h1 class="post-title">
{%- assign profile_image_class = "img-fluid z-depth-1 rounded" -%}
{% endif %}

{% include figure.html
path=profile_image_path
{% include figure.html
path=profile_image_path
class=profile_image_class
alt=page.profile.image -%}
{% endif -%}
Expand All @@ -46,6 +46,12 @@ <h2><a href="{{ '/news/' | relative_url }}" style="color: inherit;">news</a></h2
{%- include news.html %}
{%- endif %}

<!-- Latest posts -->
{% if page.latest_posts -%}
<h2><a href="{{ '/blog/' | relative_url }}" style="color: inherit;">latest posts</a></h2>
{%- include latest_posts.html %}
{%- endif %}

<!-- Selected papers -->
{% if page.selected_papers -%}
<h2><a href="{{ '/publications/' | relative_url }}" style="color: inherit;">selected publications</a></h2>
Expand All @@ -62,7 +68,7 @@ <h2><a href="{{ '/publications/' | relative_url }}" style="color: inherit;">sele
<div class="contact-note">
{{ site.contact_note }}
</div>

</div>
{%- endif %}
</article>
Expand Down
1 change: 1 addition & 0 deletions _pages/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ profile:
<p>Your City, State 12345</p>
news: true # includes a list of news items
latest_posts: true # includes a list of the newest posts
selected_papers: true # includes a list of papers marked as "selected={true}"
social: true # includes social icons at the bottom of the page
---
Expand Down

0 comments on commit 3a91ce4

Please sign in to comment.