Refactor /now to use built in postslist include
This commit is contained in:
parent
a6bd281946
commit
59484d8363
@ -3,13 +3,7 @@ layout: layouts/base.njk
|
||||
eleventyNavigation:
|
||||
key: Now
|
||||
order: 4
|
||||
numberOfLatestPostsToShow: 4
|
||||
---
|
||||
{% set postsCount = collections.now | length %}
|
||||
{% set latestPostsCount = postsCount | min(numberOfLatestPostsToShow) %}
|
||||
{% set postslist = collections.now | head(-1 * numberOfLatestPostsToShow) %}
|
||||
{% set postslistCounter = postsCount %}
|
||||
{% set morePosts = postsCount - numberOfLatestPostsToShow %}
|
||||
<article>
|
||||
<h1>Now: What’s Been Going on Lately?</h1>
|
||||
{% set now = collections.now | last %}
|
||||
@ -18,35 +12,11 @@ numberOfLatestPostsToShow: 4
|
||||
<p class="metadata">Updated: {{ now.date | readableDate }} | <a href="https://nownownow.com/about">What is a now page?</a></p>
|
||||
</article>
|
||||
|
||||
{% set postsCount = collections.now | removeMostRecent | length %}
|
||||
{% if postsCount > 1 %}
|
||||
<h2>Previous Entries:</h2>
|
||||
<section class="postlist">
|
||||
<div class="postlist-item-container">
|
||||
{% for post in postslist | reverse %}
|
||||
{% if post.data.title != now.data.title %}
|
||||
<article class="postlist-item{% if post.url == url %} postlist-item-active{% endif %}">
|
||||
<a href="{{ post.url }}" class="postlist-link">
|
||||
<div class="post-image-container">
|
||||
<img class="post-image" {% if post.data.imageURL %} src="{{ post.data.imageURL }}" alt="{{ post.data.imageAlt }}" {% else %} src="{{ metadata.defaultPostImageURL }}" alt="{{ metadata.defaultPostImageAlt }}"{% endif %}>
|
||||
</div>
|
||||
</a>
|
||||
<div class="post-copy">
|
||||
<a href="{{ post.url }}" class="postlist-link">
|
||||
<h3>
|
||||
{% if post.data.title %}{{ post.data.title }}{% else %}<code>{{ post.url }}</code>{% endif %}
|
||||
</h3>
|
||||
</a>
|
||||
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate("LLLL yyyy") }}</time>
|
||||
{% if post.data.synopsis %}<p>{{ post.data.synopsis | truncate(150) | safe }}</p>{% else %}{{ post.content | truncate(150) | safe }}{% endif %}
|
||||
</div>
|
||||
</article>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if morePosts > 0 %}
|
||||
<a href="/tags/now"><p>See {{ morePosts }} more post{% if morePosts != 1 %}s{% endif %}</a>.</p>
|
||||
{% set postslist = collections.now | removeMostRecent %}
|
||||
{% set showPostListHeader = false %}
|
||||
{% include "postslist.njk" %}
|
||||
{% endif %}
|
||||
|
||||
</section>
|
||||
|
||||
{% endif %}
|
||||
|
@ -54,6 +54,10 @@ module.exports = eleventyConfig => {
|
||||
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("removeMostRecent", arr => {
|
||||
return arr.slice(0, arr.length-1);
|
||||
});
|
||||
|
||||
// Shortcodes
|
||||
eleventyConfig.addNunjucksFilter("cowsay", cowText => {
|
||||
const cowCaptionReplacementTable = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user