mirror of
https://github.com/clockworkpi/wiki.clockworkpi.com.git
synced 2026-03-19 02:12:40 +01:00
Issue #6 List of pages per user
This commit is contained in:
22
_plugins/contributions-page-generator.rb
Normal file
22
_plugins/contributions-page-generator.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module Jekyll
|
||||
class ContributionsPageGenerator < Generator
|
||||
def generate(site)
|
||||
site.data['authors'].each do |author|
|
||||
site.pages << ContributionsPage.new(site, author)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ContributionsPage < Page
|
||||
def initialize(site, author)
|
||||
@site = site
|
||||
@base = site.source
|
||||
@name = "#{author['contributions_url']}.html"
|
||||
|
||||
self.process(@name)
|
||||
self.read_yaml(File.join(@base, '_layouts'), 'contributions.html')
|
||||
self.data['author_full'] = author
|
||||
self.data['title'] = "Contributions by <a href=\"/#{site.data['i18n'][site.config['lang']]['prefix']['user']}#{author['id']}.html\">#{author['name']}</a>"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,45 @@
|
||||
Jekyll::Hooks.register :documents, :pre_render do |post|
|
||||
Jekyll::Hooks.register :site, :post_read do |site|
|
||||
user_pages = site.collections
|
||||
.select { |key, collection| key.start_with?('special') }
|
||||
.map { |key, collection| collection.docs }
|
||||
.flatten
|
||||
.select { |page| page.data['layout'] == 'user' }
|
||||
|
||||
wiki_pages = site.collections
|
||||
.select { |key, collection| key.start_with?('wiki') }
|
||||
.map { |key, collection| collection.docs }
|
||||
.flatten
|
||||
site.data['wiki_pages'] = wiki_pages
|
||||
|
||||
wiki_tags = wiki_pages
|
||||
.map { |page| page.data['tags'] }
|
||||
.flatten
|
||||
.uniq
|
||||
site.data['wiki_tags'] = wiki_tags
|
||||
|
||||
prefix = site.data['i18n'][site.config['lang']]['prefix']['user']
|
||||
authors = site.data['users'].map do |user|
|
||||
contributions = wiki_pages.select { |page| page.data['author'] == user[0] }
|
||||
author = {'id' => user[0],
|
||||
'name' => user[1]['name'],
|
||||
'logo' => user[1]['logo'],
|
||||
'url' => "/#{prefix}#{user[0]}",
|
||||
'contributions' => contributions,
|
||||
'contributions_count' => contributions.length,
|
||||
'contributions_url' => "/#{prefix}#{user[0]}:Contributions"
|
||||
}
|
||||
user_pages.select { |page| page.url == author['url'] }
|
||||
.each { |page| page.data['author_full'] = author }
|
||||
author
|
||||
end
|
||||
site.data['authors'] = authors
|
||||
|
||||
wiki_pages.each do |page|
|
||||
page.data['author_full'] = authors.select { |author| author['id'] == page.data['author'] }.first
|
||||
end
|
||||
end
|
||||
|
||||
Jekyll::Hooks.register :documents, :post_render do |doc|
|
||||
# Jekyll.logger.info "Generating:", "Firing :pages, :post_render for : #{post.content}"
|
||||
if doc.content then
|
||||
doc.data['size']=doc.content.size
|
||||
doc.data['bytes']=doc.content.bytesize
|
||||
|
||||
Reference in New Issue
Block a user