Skip to content

Commit

Permalink
Generate the regex for removing a slug's extension once
Browse files Browse the repository at this point in the history
  • Loading branch information
benpickles committed Sep 23, 2024
1 parent 91f2555 commit 612404b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/decant/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def slug_for(path)

# The collection has no configured extension, files are identified by
# their full (relative) path so there's no extension to remove.
return relative_path if ext.nil?
return relative_path if @delete_ext_regexp.nil?

regexp = PathUtils.delete_ext_regexp(ext)
relative_path.sub(regexp, '')
relative_path.sub(@delete_ext_regexp, '')
end

private
Expand All @@ -43,8 +42,10 @@ def dir=(value)
def ext=(value)
if value
@ext = value.start_with?('.') ? value : ".#{value}"
@delete_ext_regexp = PathUtils.delete_ext_regexp(ext)
else
@ext = value
@ext = nil
@delete_ext_regexp = nil
end
end
end
Expand Down

0 comments on commit 612404b

Please sign in to comment.