class Jekyll::AuthorsGenerator

Public Instance Methods

authors(file) click to toggle source

Gets the authors and then adds required formatting.

# File lib/jekyll-git-authors.rb, line 40
def authors(file)
  author_md = Git.log(file).author_email
  author_md = author_md.sort
  author_md = author_md.map { |a, e| Markdown.mailto(a, e) }

  output = author_md.join ', '
  output = "Authors: #{output}"
  Markdown.center output
end
generate(site) click to toggle source

iterate through pages then pick those which are are markdown file then call Git#log on the page and add authors into its content

# File lib/jekyll-git-authors.rb, line 17
def generate(site)
  puts "\nGenerating authors"

  # Find every .md file that is in subdirectory,
  # then go into directory where page is located.
  # Git finds authors for us if we call Git#log in directory
  # where the file is located.
  site.pages.each do |page|
    file = page.path
    # If file ends with md and if it is subdir.
    # Jekyll does not add "./" into pages paths,
    # so we can use this approach.
    if file =~ /\.md/ and file =~ /\//
      Dir.chdir File.dirname(file) do |path|
        output = authors File.basename(file)

        page.content += output
      end
    end
  end
end