mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Add "Network status and alerts" page and RSS feed (fixes #170)
Generate alerts pages through alerts.rb plugin Allow to keep short alias urls for each alert Move alert pages in _alerts Update sitemap plugin to include alerts
This commit is contained in:
parent
cd597fdb21
commit
ec44853934
18 changed files with 385 additions and 54 deletions
49
_plugins/alerts.rb
Normal file
49
_plugins/alerts.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'yaml'
|
||||
|
||||
module Jekyll
|
||||
|
||||
class AlertPage < Page
|
||||
def initialize(site, base, lang, srcdir, src, dstdir, dst, date)
|
||||
@site = site
|
||||
@base = base
|
||||
@dir = '/'+dstdir
|
||||
@name = dst
|
||||
self.process(dst)
|
||||
self.read_yaml(File.join(base, srcdir), src)
|
||||
self.data['lang'] = lang
|
||||
self.data['date'] = date
|
||||
self.data['layout'] = 'alert'
|
||||
if dstdir == ''
|
||||
self.data['redirect'] = src.split('.')[0]
|
||||
else
|
||||
self.data['category'] = 'alert'
|
||||
if self.data.has_key?('alias')
|
||||
site.pages << AlertPage.new(site, base, lang, srcdir, src, '', self.data['alias']+'.html', date)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class AlertPageGenerator < Generator
|
||||
def generate(site)
|
||||
#generate each alert based on templates
|
||||
Dir.foreach('_alerts') do |file|
|
||||
next if file == '.' or file == '..'
|
||||
lang = 'en'
|
||||
src = file
|
||||
dst = file
|
||||
srcdir = '_alerts'
|
||||
dstdir = lang + '/alert'
|
||||
date = dst.split('-')
|
||||
next if date.length < 4
|
||||
date = date[0] + '-' + date[1] + '-' + date[2]
|
||||
next if !/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.match(date)
|
||||
site.pages << AlertPage.new(site, site.source, lang, '_alerts', src, dstdir, dst, date)
|
||||
end
|
||||
#TODO alerts are only generated for english language,
|
||||
#but they could also be translated at some point. They would however
|
||||
#need to fallback to english when no translation is available.
|
||||
end
|
||||
end
|
||||
|
||||
end
|
49
_plugins/catpage_for.rb
Normal file
49
_plugins/catpage_for.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
#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 %}
|
||||
|
||||
module Jekyll
|
||||
module SortedForImpl
|
||||
def render(context)
|
||||
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
|
||||
s = []
|
||||
for x in sorted_collection
|
||||
if x.to_liquid.has_key?('category') && x.to_liquid['category'] == category_attr
|
||||
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] }
|
||||
#return modified array
|
||||
original_name = @collection_name
|
||||
result = nil
|
||||
context.stack do
|
||||
sorted_collection_name = "#{@collection_name}_sorted".sub('.', '_')
|
||||
context[sorted_collection_name] = sorted_collection
|
||||
@collection_name = sorted_collection_name
|
||||
result = super
|
||||
@collection_name = original_name
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
class SortedForTag < Liquid::For
|
||||
include SortedForImpl
|
||||
|
||||
def collection_to_sort(context)
|
||||
return context[@collection_name].dup
|
||||
end
|
||||
|
||||
def end_tag
|
||||
'endcatpage_for'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('catpage_for', Jekyll::SortedForTag)
|
|
@ -66,6 +66,13 @@ module Jekyll
|
|||
sitemap.puts ' <loc>http://bitcoin.org/'+file1.gsub('.html','')+'</loc>'
|
||||
sitemap.puts '</url>'
|
||||
end
|
||||
#Add english alerts pages
|
||||
Dir.foreach('_alerts') do |file|
|
||||
next if file == '.' or file == '..'
|
||||
sitemap.puts '<url>'
|
||||
sitemap.puts ' <loc>http://bitcoin.org/en/alert/'+file.gsub('.html','')+'</loc>'
|
||||
sitemap.puts '</url>'
|
||||
end
|
||||
#Add posts
|
||||
site.posts.each do |post|
|
||||
sitemap.puts '<url>'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue