Class: Jekyll::Authors::AuthorUrlTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-authors.rb

Overview

Returns a correctly formatted author url based on site configuration.

Use without arguments to return the url of the author list page.

{% author_url %}

Use with argument to return the url of a specific catogory page. The argument can be either a string or a variable in the current context.

{% author_url author_name %}
{% author_url author_var %}

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ AuthorUrlTag

Returns a new instance of AuthorUrlTag.



132
133
134
135
# File 'lib/jekyll-authors.rb', line 132

def initialize(tag_name, text, tokens)
  super
  @author = text
end

Instance Method Details

#render(context) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/jekyll-authors.rb', line 137

def render(context)
  base_url = context.registers[:site].config['base-url'] || '/'
  author_dir = context.registers[:site].config['author_dir'] || 'authors'

  author = context[@author] || @author.strip.tr(' ', '-').downcase
  author.empty? ? "#{base_url}#{author_dir}" : "#{base_url}#{author_dir}/#{author}"
end