"Referred article" functionality
This commit is contained in:
parent
607b76daab
commit
29a963733d
3 changed files with 29 additions and 21 deletions
|
|
@ -1,15 +1,3 @@
|
||||||
<%
|
|
||||||
def sanitize_path(path)
|
|
||||||
result = path
|
|
||||||
if (!path.start_with?('/'))
|
|
||||||
result = '/' + result
|
|
||||||
end
|
|
||||||
if (!path.end_with?('/'))
|
|
||||||
result = result + '/'
|
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span8">
|
<div class="span8">
|
||||||
<article itemscope itemtype="http://schema.org/BlogPosting">
|
<article itemscope itemtype="http://schema.org/BlogPosting">
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,16 @@
|
||||||
<div class="span8">
|
<div class="span8">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span8">
|
<div class="span8">
|
||||||
<h1><%= item[:title] %></h1>
|
<h1><%= item[:title] %></h1>
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
</div>
|
</div>
|
||||||
<div class="span8">
|
<% latest_articles_referred_to(item.identifier,5).each do |item| %>
|
||||||
<h1>Ein Projektartikel</h1>
|
<div class="span8">
|
||||||
</div>
|
<%= render 'article_intro', :article => item, :extended => true %>
|
||||||
<div class="span8">
|
<p>
|
||||||
<h1>Noch ein Projektartikel</h1>
|
<a itemprop="blogPost" href="<%= item.path() %>">Zum Artikel</a>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="span4">
|
<div class="span4">
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,16 @@ def pathname_of_article(item)
|
||||||
time.strftime('%Y-%m-%d') + '-' + slug
|
time.strftime('%Y-%m-%d') + '-' + slug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitize_path(path)
|
||||||
|
result = path
|
||||||
|
if (!path.start_with?('/'))
|
||||||
|
result = '/' + result
|
||||||
|
end
|
||||||
|
if (!path.end_with?('/'))
|
||||||
|
result = result + '/'
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
def latest_articles(max=nil)
|
def latest_articles(max=nil)
|
||||||
@cache_latest_art ||= @site.items.select do |p|
|
@cache_latest_art ||= @site.items.select do |p|
|
||||||
|
|
@ -29,3 +39,12 @@ def latest_articles(max=nil)
|
||||||
@cache_latest_art[0..(max ? max-1 : @cache_latest_art.length-1)]
|
@cache_latest_art[0..(max ? max-1 : @cache_latest_art.length-1)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def latest_articles_referred_to(refers_to, max=nil)
|
||||||
|
refers_to = sanitize_path(refers_to)
|
||||||
|
@site.items.select do |p|
|
||||||
|
p.attributes[:kind]=='article' && p.attributes[:refers_to] && sanitize_path(p.attributes[:refers_to])==refers_to
|
||||||
|
end.sort do |a, b|
|
||||||
|
a.attributes[:created_at] <=> b.attributes[:created_at]
|
||||||
|
end.reverse[0..(max ? max-1 : @cache_latest_art.length-1)]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue