Class: Perron::Resource::Slug

Inherits:
Object
  • Object
show all
Defined in:
lib/perron/resource/slug.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource, frontmatter) ⇒ Slug

Returns a new instance of Slug.



10
11
12
13
# File 'lib/perron/resource/slug.rb', line 10

def initialize(resource, frontmatter)
  @resource = resource
  @frontmatter = frontmatter
end

Instance Method Details

#createObject



15
16
17
18
19
20
# File 'lib/perron/resource/slug.rb', line 15

def create
  return "/" if Perron.configuration.allowed_extensions.any? { @resource.filename == "root.#{it}" }

  @frontmatter.slug.presence ||
    @resource.filename.sub(/^[\d-]+-/, "").delete_suffixes(dot_prepended_allowed_extensions)
end