mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Improve catpage_for.rb
Allow to filter pages with many pages variables Allow to filter pages using dynamic variables as values
This commit is contained in:
parent
96f7a4c727
commit
33dc7127bf
5 changed files with 28 additions and 20 deletions
|
@ -1,6 +1,8 @@
|
|||
#catpage_for allows to loop in site.pages sorted by custom page
|
||||
#variables and filtered by page.category.
|
||||
#Example : {% catpage_for p in site.pages sort_by:date category:release %}
|
||||
#filter_for allows to loop in site.pages sorted and filtered
|
||||
#by custom page variables. Example :
|
||||
#{% filter_for p in site.pages sort_by:date category:release lang:{{page.lang}} %}
|
||||
# ..
|
||||
#{% endfilter_for %}
|
||||
|
||||
module Jekyll
|
||||
module SortedForImpl
|
||||
|
@ -8,17 +10,23 @@ module Jekyll
|
|||
sorted_collection = collection_to_sort context
|
||||
return if sorted_collection.empty?
|
||||
sort_attr = @attributes['sort_by']
|
||||
category_attr = @attributes['category']
|
||||
#filter page by given category
|
||||
@attributes.delete('sort_by')
|
||||
#filter page by given attributes
|
||||
s = []
|
||||
for x in sorted_collection
|
||||
if x.to_liquid.has_key?('category') && x.to_liquid['category'] == category_attr
|
||||
catch :root do
|
||||
@attributes.each do |at,atval|
|
||||
atval = Liquid::Template.parse(atval).render context
|
||||
throw :root unless x.to_liquid.has_key?(at) and x.to_liquid[at] == atval
|
||||
end
|
||||
s.push(x)
|
||||
end
|
||||
end
|
||||
sorted_collection = s
|
||||
#sort collection by given variable
|
||||
sorted_collection = sorted_collection.sort_by { |i| i.to_liquid[sort_attr] }
|
||||
if sorted_collection.length > 1
|
||||
sorted_collection = sorted_collection.sort_by { |i| i.to_liquid[sort_attr] }
|
||||
end
|
||||
#return modified array
|
||||
original_name = @collection_name
|
||||
result = nil
|
||||
|
@ -41,9 +49,9 @@ module Jekyll
|
|||
end
|
||||
|
||||
def end_tag
|
||||
'endcatpage_for'
|
||||
'endfilter_for'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('catpage_for', Jekyll::SortedForTag)
|
||||
Liquid::Template.register_tag('filter_for', Jekyll::SortedForTag)
|
|
@ -7,25 +7,25 @@ title: Network status and alerts - Bitcoin
|
|||
<link rel="alternate" type="application/rss+xml" href="/en/rss/alerts.rss" title="Bitcoin network status and alerts">
|
||||
<div class="versiontext">
|
||||
<h1>Network status and alerts<a type="application/rss+xml" href="/en/rss/alerts.rss"><img src="/img/icon_rss.svg" alt="rss" class="rssicon"></a></h1>
|
||||
{% assign active = false %}{% catpage_for p in site.pages reversed sort_by:date category:alert %}{% if p.active == true %}{% assign active = true %}{% endif %}{% endcatpage_for %}
|
||||
{% assign active = false %}{% filter_for p in site.pages reversed sort_by:date category:alert %}{% if p.active == true %}{% assign active = true %}{% endif %}{% endfilter_for %}
|
||||
{% if active == false %}
|
||||
<div class="alertstatusinactive">There is no ongoing event on the Bitcoin network.</div>
|
||||
{% else %}
|
||||
<div class="alertstatusactive"">The following network event is ongoing.</div>
|
||||
<ul class="alertsactive">
|
||||
{% catpage_for p in site.pages reversed sort_by:date category:alert %}{% if p.active == true %}
|
||||
{% filter_for p in site.pages reversed sort_by:date category:alert %}{% if p.active == true %}
|
||||
<li>
|
||||
{{ p.date | date:"%Y-%m-%d" }} - <a href="{{ p.url | replace:'.html','' }}">{{ p.title }}</a>
|
||||
</li>
|
||||
{% endif %}{% endcatpage_for %}
|
||||
{% endif %}{% endfilter_for %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
<ul class="alertsinactive">
|
||||
{% catpage_for p in site.pages reversed sort_by:date category:alert %}{% if p.active == false %}
|
||||
{% filter_for p in site.pages reversed sort_by:date category:alert %}{% if p.active == false %}
|
||||
<li>
|
||||
{{ p.date | date:"%Y-%m-%d" }} - <a href="{{ p.url | replace:'.html','' }}">{{ p.title }}</a>
|
||||
</li>
|
||||
{% endif %}{% endcatpage_for %}
|
||||
{% endif %}{% endfilter_for %}
|
||||
</ul>
|
||||
<p>See the complete <a href="https://en.bitcoin.it/wiki/Common_Vulnerabilities_and_Exposures">CVE list</a>.</p>
|
||||
</div>
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
<url>http://bitcoin.org/img/logo_rss.png</url>
|
||||
<link>http://bitcoin.org/en/alerts</link>
|
||||
</image>
|
||||
{% catpage_for p in site.pages reversed sort_by:date category:alert %}
|
||||
{% filter_for p in site.pages reversed sort_by:date category:alert %}
|
||||
<item>
|
||||
<title>{{ p.title }}</title>
|
||||
<link>http://bitcoin.org{{ p.url | replace:'.html','' }}</link>
|
||||
<pubDate>{{ p.date | date: "%a, %d %b %Y" }}</pubDate>
|
||||
</item>
|
||||
{% endcatpage_for %}
|
||||
{% endfilter_for %}
|
||||
</channel>
|
||||
</rss>
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
<url>http://bitcoin.org/img/logo_rss.png</url>
|
||||
<link>http://bitcoin.org/en/version-history</link>
|
||||
</image>
|
||||
{% catpage_for p in site.pages reversed sort_by:date category:release %}
|
||||
{% filter_for p in site.pages reversed sort_by:date category:release %}
|
||||
<item>
|
||||
<title>{{ p.title }}</title>
|
||||
<link>http://bitcoin.org{{ p.url | replace:'.html','' }}</link>
|
||||
<pubDate>{{ p.date | date: "%a, %d %b %Y" }}</pubDate>
|
||||
</item>
|
||||
{% endcatpage_for %}
|
||||
{% endfilter_for %}
|
||||
</channel>
|
||||
</rss>
|
||||
|
|
|
@ -8,10 +8,10 @@ title: Bitcoin-Qt version history
|
|||
<div class="versiontext">
|
||||
<h1>Bitcoin-Qt version history<a type="application/rss+xml" href="/en/rss/releases.rss"><img src="/img/icon_rss.svg" alt="rss" class="rssicon"></a></h1>
|
||||
<ul>
|
||||
{% catpage_for p in site.pages reversed sort_by:date category:release %}
|
||||
{% filter_for p in site.pages reversed sort_by:date category:release %}
|
||||
<li>
|
||||
{{ p.date | date:"%Y-%m-%d" }} - <a href="{{ p.url | replace:'.html','' }}">{{ p.title }}</a>
|
||||
</li>
|
||||
{% endcatpage_for %}
|
||||
{% endfilter_for %}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue