Skip to content

Commit

Permalink
✨ set new! for fresh posts
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwoo-joh committed Feb 8, 2022
1 parent 034e00f commit 276090e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="google-site-verification" content="fgTBOMeN_sdI4JNBqYTzDwH0458H8AAVbF78jLjwudg" />
<script type="text/javascript" src="{{ '/assets/vendor/moment.min.js' | relative_url }}"></script>

<title>
{% if page.title %}
Expand Down
15 changes: 13 additions & 2 deletions _includes/post_list.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<ul>
{% for post in site.posts %}

{% assign post_date = post.date | date: site.theme_config.date_format %}
<li>
{{ post.date | date: site.theme_config.date_format }} <a href="{{ post.url | relative_url }}">{{ post.title | downcase }}</a>
<div class="new" data-post-date="{{ post_date}}">{{ post_date }} <a href="{{ post.url | relative_url }}">{{ post.title | downcase }}</a></div>
</li>

{% endfor %}
</ul>

<script type="text/javascript">
let posts = document.getElementsByClassName("new");
const now = moment();
for (let post_date of posts) {
let pdate = moment(post_date.dataset.postDate);
if (now.isoWeek() == pdate.isoWeek()) {
post_date.innerHTML = "<b>[new!]</b> " + post_date.textContent;
}
}
</script>
2 changes: 2 additions & 0 deletions assets/vendor/moment.min.js

Large diffs are not rendered by default.

0 comments on commit 276090e

Please sign in to comment.