From 12e8b659158681f4f47ab30e3e550def19928a38 Mon Sep 17 00:00:00 2001 From: George Moura Date: Sun, 1 May 2016 22:14:16 -0300 Subject: [PATCH] add authors page --- _plugins/authors.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ _sass/_layout.scss | 2 ++ authors.html | 9 +++++++++ 3 files changed, 55 insertions(+) create mode 100644 _plugins/authors.rb create mode 100644 authors.html diff --git a/_plugins/authors.rb b/_plugins/authors.rb new file mode 100644 index 0000000..d30c85e --- /dev/null +++ b/_plugins/authors.rb @@ -0,0 +1,44 @@ +require 'digest/md5' +module Jekyll + + class Author + attr_accessor :author, :posts + def initialize(author, posts) + self.author = author + self.posts = posts + end + + def to_liquid + hash = Digest::MD5.hexdigest(self.author['mail']) + text = "

#{self.author['name']}

" + text += "

Posts:

" + text += "" + text + end + end + + class AuthorsPageGenerator < Generator + safe true + + def generate(site) + authors = {} + site.posts.docs.each do |post| + if !authors[post.data["author"]["github"]].nil? + authors[post.data["author"]["github"]][:posts] << {:url => post.url, :title => post.data["title"]} + else + authors[post.data["author"]["github"]] = {:author => post.data["author"], :posts => [{:url => post.url, :title => post.data["title"]}]} + end + end + authors_page = site.pages.detect {|page| page.name == 'authors.html'} + authors_page.data['authors'] = [] + authors.each do |author, post_data| + authors_page.data['authors'] << Author.new(post_data[:author], post_data[:posts]) + end + end + end + +end diff --git a/_sass/_layout.scss b/_sass/_layout.scss index 29b5e1c..dceb8ba 100644 --- a/_sass/_layout.scss +++ b/_sass/_layout.scss @@ -429,3 +429,5 @@ pre code.hljs { } } } + +.gravatar{ width: 100px;} diff --git a/authors.html b/authors.html new file mode 100644 index 0000000..e1655ac --- /dev/null +++ b/authors.html @@ -0,0 +1,9 @@ +--- +layout: page +title: "Autores" +permalink: /authors/ +--- + {% for author in page.authors %} + {{ author }} +
+ {% endfor %}