From 1ea3b38234a71e41c9bccc66f12b7199f4c26fea Mon Sep 17 00:00:00 2001 From: Stefan Schlott Date: Tue, 26 Sep 2017 09:08:44 +0200 Subject: [PATCH] Filter latest articles: Time limit --- content/htaccess.txt | 2 +- lib/articlehelpers.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/content/htaccess.txt b/content/htaccess.txt index fcaddaf3..1ac47526 100644 --- a/content/htaccess.txt +++ b/content/htaccess.txt @@ -2,7 +2,7 @@ ErrorDocument 404 /404/index.html RedirectMatch 303 ^/events/$ /events/<%= Time.now.year %>/ RedirectMatch 303 ^/activities/$ /activities/<%= Time.now.year %>/ -RedirectMatch 303 ^/archives/articles/$ /archives/articles/<%= latest_articles(1)[0][:created_at].year %>/ +RedirectMatch 303 ^/archives/articles/$ /archives/articles/<%= Time.now.year %>/ RedirectMatch 303 ^/archives/twitter/$ /archives/twitter/<%= twitter_grouped_by_month.keys.sort.last %>/ RedirectMatch 301 ^/wiki$ / diff --git a/lib/articlehelpers.rb b/lib/articlehelpers.rb index ecbdb528..11a9584b 100644 --- a/lib/articlehelpers.rb +++ b/lib/articlehelpers.rb @@ -1,3 +1,6 @@ +require 'date' + + def article_base_item(item) idparts = item.identifier.split('/') articleid = "/#{idparts[1]}/#{idparts[2]}/" @@ -31,8 +34,9 @@ def sanitize_path(path) end def latest_articles(max=nil) + threshold = Date.today - 90 # Show articles for 90 days @cache_latest_art ||= @site.items.select do |p| - p.attributes[:kind] == 'article' + p.attributes[:kind] == 'article' and p.attributes[:created_at] > threshold end.sort do |a, b| a.attributes[:created_at] <=> b.attributes[:created_at] end.reverse