Method: Middleman::Blog::BlogArticle#slug

Defined in:
lib/middleman-blog/blog_article.rb

#slugString

The “slug” of the article that shows up in its URL. The article slug is a parametrized version of the #title (lowercase, spaces replaced with dashes, etc) and can be used in the blog permalink as :title.

Returns:

  • (String)


242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/middleman-blog/blog_article.rb', line 242

def slug
  if data['slug']
    Blog::UriTemplates.safe_parameterize(data['slug'])

  elsif blog_data.source_template.variables.include?('title')
    Blog::UriTemplates.safe_parameterize(path_part('title'))

  elsif title
    Blog::UriTemplates.safe_parameterize(title)

  else
    raise "Can't generate a slug for #{path} because it has no :title in its path pattern or title/slug in its frontmatter."

  end
end