Skip to content

Commit

Permalink
displays latest news by default on homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaskundig committed Jun 30, 2021
1 parent 389af5e commit f2eeb32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion conf/netlify/cms/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ collections:
widget: markdown, buttons: [bold, italic, link], editor_components: [], minimal: true}
- label: "News"
name: "news"
hint: "Posts added here will be displayed instead of the latest news"
widget: "list"
i18n: true
max: 3
max: 4
types:
- label: "Editorial"
name: "editorial"
Expand Down
26 changes: 25 additions & 1 deletion src/site/_layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,33 @@ <h2>{% inlineMarkdown paragraph.title %}</h2>

{% if news | length %}
<section id="news">
<h1>{% inlineMarkdown news_title %}</h1> enabled to see
<h1>{% inlineMarkdown news_title %}</h1>
<noscript>You need JavaScript enabled to see
the additional news articles hereafter.</noscript>
<div class="grid-layout-halves with-gutters">
{% set latest_news = collections.blogPosts[locale].latest %}
{% set max_latest = latest_news.length - news.length %}
{% set latest_count = 0 %}
{% for post in latest_news %}
{% if latest_count < max_latest %}
{% set display = true %}
{% for chosen in news %}
{% set display = display and chosen.post != post.data.id %}
{% endfor %}
{% if display %}
{% set latest_count = latest_count + 1 %}
<article-breakout
class="grid-cell" layout="box"
href="{{post.url | url}}"
img-src="{{post.data | getLocalizedOrDefault("image") | url}}">
<span slot="caption">{% inlineMarkdown post.data| getLocalizedOrDefault("image_caption") %}</span>
<h2>{% inlineMarkdown post.data.title %}</h2>
{% markdown post.data.lead %}
<button>{{i18n.globals[locale].read_more}}</button>
</article-breakout>
{% endif %}
{% endif %}
{% endfor %}
{% for item in news %}
{% for post in collections[item.type] %}
{% if post.data.locale == locale and post.data.id == item.post %}
Expand Down

0 comments on commit f2eeb32

Please sign in to comment.