Skip to content

Commit

Permalink
feat: add pinned posts
Browse files Browse the repository at this point in the history
  • Loading branch information
César Román committed Apr 2, 2023
1 parent f411d66 commit 154e384
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 0 deletions.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ round-avatar: true
social-network-links:
email: "[email protected]"
github: thecesrom
mastodon: fosstodon.org/@thecesrom
twitter: thecesrom

# If you want to show a link to an RSS in the footer, add the site description here.
Expand Down
204 changes: 204 additions & 0 deletions _layouts/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
---
layout: page
---

{{ content }}

{% assign posts = paginator.posts | default: site.posts %}

<!-- role="list" needed so that `list-style: none` in Safari doesn't remove the list semantics -->
<ul class="posts-list list-unstyled" role="list">
{% if page.url == "/" %}
{% for post in site.tags.pinned %}
<li class="post-preview">
<article>

{%- capture thumbnail -%}
{% if post.thumbnail-img %}
{{ post.thumbnail-img }}
{% elsif post.cover-img %}
{% if post.cover-img.first %}
{{ post.cover-img[0].first.first }}
{% else %}
{{ post.cover-img }}
{% endif %}
{% else %}
{% endif %}
{% endcapture %}
{% assign thumbnail=thumbnail | strip %}

{% if site.feed_show_excerpt == false %}
{% if thumbnail != "" %}
<div class="post-image post-image-normal">
<a href="{{ post.url | absolute_url }}" aria-label="Thumbnail">
<img src="{{ thumbnail | absolute_url }}" alt="Post thumbnail">
</a>
</div>
{% endif %}
{% endif %}

<a href="{{ post.url | absolute_url }}">
<h2 class="post-title">📌 {{ post.title | strip_html }}</h2>

{% if post.subtitle %}
<h3 class="post-subtitle">
{{ post.subtitle | strip_html }}
</h3>
{% endif %}
</a>

<p class="post-meta">
{% assign date_format = site.date_format | default: "%B %-d, %Y" %}
Posted on {{ post.date | date: date_format }}
</p>

{% if thumbnail != "" %}
<div class="post-image post-image-small">
<a href="{{ post.url | absolute_url }}" aria-label="Thumbnail">
<img src="{{ thumbnail | absolute_url }}" alt="Post thumbnail">
</a>
</div>
{% endif %}

{% unless site.feed_show_excerpt == false %}
{% if thumbnail != "" %}
<div class="post-image post-image-short">
<a href="{{ post.url | absolute_url }}" aria-label="Thumbnail">
<img src="{{ thumbnail | absolute_url }}" alt="Post thumbnail">
</a>
</div>
{% endif %}

<div class="post-entry">
{% assign excerpt_length = site.excerpt_length | default: 50 %}
{{ post.excerpt | strip_html | truncatewords: excerpt_length }}
{% assign excerpt_word_count = post.excerpt | number_of_words %}
{% if post.content != post.excerpt or excerpt_word_count > excerpt_length %}
<a href="{{ post.url | absolute_url }}" class="post-read-more">[Read&nbsp;More]</a>
{% endif %}
</div>
{% endunless %}

{% if site.feed_show_tags != false and post.tags.size > 0 %}
<div class="blog-tags">
<span>Tags:</span>
<!-- role="list" needed so that `list-style: none` in Safari doesn't remove the list semantics -->
<ul class="d-inline list-inline" role="list">
{% for tag in post.tags %}
<li class="list-inline-item">
<a href="{{ '/tags' | absolute_url }}#{{- tag -}}">{{- tag -}}</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}

</article>
</li>
{% endfor %}
{% endif %}
{% for post in posts %}
{% unless post.tags contains 'pinned' %}
<li class="post-preview">
<article>

{%- capture thumbnail -%}
{% if post.thumbnail-img %}
{{ post.thumbnail-img }}
{% elsif post.cover-img %}
{% if post.cover-img.first %}
{{ post.cover-img[0].first.first }}
{% else %}
{{ post.cover-img }}
{% endif %}
{% else %}
{% endif %}
{% endcapture %}
{% assign thumbnail=thumbnail | strip %}

{% if site.feed_show_excerpt == false %}
{% if thumbnail != "" %}
<div class="post-image post-image-normal">
<a href="{{ post.url | absolute_url }}" aria-label="Thumbnail">
<img src="{{ thumbnail | absolute_url }}" alt="Post thumbnail">
</a>
</div>
{% endif %}
{% endif %}

<a href="{{ post.url | absolute_url }}">
<h2 class="post-title">{{ post.title | strip_html }}</h2>

{% if post.subtitle %}
<h3 class="post-subtitle">
{{ post.subtitle | strip_html }}
</h3>
{% endif %}
</a>

<p class="post-meta">
{% assign date_format = site.date_format | default: "%B %-d, %Y" %}
Posted on {{ post.date | date: date_format }}
</p>

{% if thumbnail != "" %}
<div class="post-image post-image-small">
<a href="{{ post.url | absolute_url }}" aria-label="Thumbnail">
<img src="{{ thumbnail | absolute_url }}" alt="Post thumbnail">
</a>
</div>
{% endif %}

{% unless site.feed_show_excerpt == false %}
{% if thumbnail != "" %}
<div class="post-image post-image-short">
<a href="{{ post.url | absolute_url }}" aria-label="Thumbnail">
<img src="{{ thumbnail | absolute_url }}" alt="Post thumbnail">
</a>
</div>
{% endif %}

<div class="post-entry">
{% assign excerpt_length = site.excerpt_length | default: 50 %}
{{ post.excerpt | strip_html | truncatewords: excerpt_length }}
{% assign excerpt_word_count = post.excerpt | number_of_words %}
{% if post.content != post.excerpt or excerpt_word_count > excerpt_length %}
<a href="{{ post.url | absolute_url }}" class="post-read-more">[Read&nbsp;More]</a>
{% endif %}
</div>
{% endunless %}

{% if site.feed_show_tags != false and post.tags.size > 0 %}
<div class="blog-tags">
<span>Tags:</span>
<!-- role="list" needed so that `list-style: none` in Safari doesn't remove the list semantics -->
<ul class="d-inline list-inline" role="list">
{% for tag in post.tags %}
<li class="list-inline-item">
<a href="{{ '/tags' | absolute_url }}#{{- tag -}}">{{- tag -}}</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}

</article>
</li>
{% endunless %}
{% endfor %}
</ul>

{% if paginator.total_pages > 1 %}
<ul class="pagination main-pager">
{% if paginator.previous_page %}
<li class="page-item previous">
<a class="page-link" href="{{ paginator.previous_page_path | absolute_url }}">&larr; Newer Posts</a>
</li>
{% endif %}
{% if paginator.next_page %}
<li class="page-item next">
<a class="page-link" href="{{ paginator.next_page_path | absolute_url }}">Older Posts &rarr;</a>
</li>
{% endif %}
</ul>
{% endif %}
1 change: 1 addition & 0 deletions _posts/2023-02-07-upcoming-articles-in-2023.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tags:
- python3
- terminal
- ubuntu
- pinned
date: 2023-02-07 14:13 -0800
---
Hello, readers!
Expand Down

0 comments on commit 154e384

Please sign in to comment.