Class: Jekyll::AuthorsGenerator

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-git-authors.rb

Instance Method Summary collapse

Instance Method Details

#authors(file) ⇒ Object

Gets the authors and then adds required formatting.



40
41
42
43
44
45
46
47
48
# 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) ⇒ Object

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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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