class Jekyll::AuthorsGenerator
Public Class Methods
new(config = {})
click to toggle source
Calls superclass method
# File lib/jekyll-git-authors.rb, line 13 def initialize(config = {}) super(config) @options = { 'max_authors' => 5, 'center' => true, 'thematic_break' => true, 'prefix' => 'Authors:' }.merge(config['git_authors'] || {}) end
Public Instance Methods
format(authors)
click to toggle source
# File lib/jekyll-git-authors.rb, line 59 def format(authors) markdown = JekyllGitAuthors::Markdown.new authors.map(&:to_markdown).join(', ') markdown = markdown.prefix(@options['prefix']) markdown = markdown.center if @options['center'] markdown = markdown.thematic_break if @options['thematic_break'] markdown.to_s 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 27 def generate(site) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize Jekyll.logger.info 'Git authors:', 'Generating authors...' site.pages.each do |page| page_path = 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. next unless page_path =~ /\.md/ && page_path =~ /\// Dir.chdir File.dirname(page_path) do begin output = authors File.basename(page_path) rescue JekyllGitAuthors::Git::ExecutionError => e Jekyll.logger.error 'Error:', "Git authors: #{page_path} is not in git, cannot generate authors." Jekyll.logger.error 'Git authors failed,', " Command: '#{e.command}', Git: '#{e.stderr}'" break end Jekyll.logger.debug 'Git authors:', 'Generating authors for ' + page_path.to_s page.content += output end end end