"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="span8">
|
||||
<article itemscope itemtype="http://schema.org/BlogPosting">
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@
|
|||
<div class="span8">
|
||||
<div class="row">
|
||||
<div class="span8">
|
||||
<h1><%= item[:title] %></h1>
|
||||
<%= yield %>
|
||||
</div>
|
||||
<div class="span8">
|
||||
<h1>Ein Projektartikel</h1>
|
||||
</div>
|
||||
<div class="span8">
|
||||
<h1>Noch ein Projektartikel</h1>
|
||||
</div>
|
||||
<h1><%= item[:title] %></h1>
|
||||
<%= yield %>
|
||||
</div>
|
||||
<% latest_articles_referred_to(item.identifier,5).each do |item| %>
|
||||
<div class="span8">
|
||||
<%= render 'article_intro', :article => item, :extended => true %>
|
||||
<p>
|
||||
<a itemprop="blogPost" href="<%= item.path() %>">Zum Artikel</a>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
|
|
|
|||
|
|
@ -19,6 +19,16 @@ def pathname_of_article(item)
|
|||
time.strftime('%Y-%m-%d') + '-' + slug
|
||||
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)
|
||||
@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)]
|
||||
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