Skip to content

Commit

Permalink
Refactor to remove redundant calls and variables (#240)
Browse files Browse the repository at this point in the history
Merge pull request 240
  • Loading branch information
ashmaroli authored and jekyllbot committed Sep 9, 2018
1 parent 294b131 commit 2a82f18
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
2 changes: 1 addition & 1 deletion jekyll-feed.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "nokogiri", "~> 1.6"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "~> 0.57.2"
spec.add_development_dependency "rubocop", "~> 0.57.2"
spec.add_development_dependency "typhoeus", ">= 0.7", "< 2.0"
end
36 changes: 16 additions & 20 deletions lib/jekyll-feed/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def generate(site)

# Returns the plugin's config or an empty hash if not set
def config
@site.config["feed"] || {}
@config ||= @site.config["feed"] || {}
end

# Determines the destination path of a given feed
Expand All @@ -42,13 +42,9 @@ def config
# Will return `/feed/collection/category.xml` for other collection categories
def feed_path(collection: "posts", category: nil)
prefix = collection == "posts" ? "/feed" : "/feed/#{collection}"
if category
"#{prefix}/#{category}.xml"
elsif collections[collection] && collections[collection]["path"]
collections[collection]["path"]
else
"#{prefix}.xml"
end
return "#{prefix}/#{category}.xml" if category

collections.dig(collection, "path") || "#{prefix}.xml"
end

# Returns a hash representing all collections to be processed and their metadata
Expand All @@ -65,7 +61,7 @@ def collections
end

@collections = normalize_posts_meta(@collections)
@collections.each do |_name, meta|
@collections.each_value do |meta|
meta["categories"] = (meta["categories"] || []).to_set
end

Expand All @@ -89,17 +85,17 @@ def file_exists?(file_path)
# Generates contents for a file

def make_page(file_path, collection: "posts", category: nil)
file = PageWithoutAFile.new(@site, __dir__, "", file_path)
file.content = feed_template
file.data.merge!({
"layout" => nil,
"sitemap" => false,
"xsl" => file_exists?("feed.xslt.xml"),
"collection" => collection,
"category" => category,
})
file.output
file
PageWithoutAFile.new(@site, __dir__, "", file_path).tap do |file|
file.content = feed_template
file.data.merge!(
"layout" => nil,
"sitemap" => false,
"xsl" => file_exists?("feed.xslt.xml"),
"collection" => collection,
"category" => category
)
file.output
end
end

# Special case the "posts" collection, which, for ease of use and backwards
Expand Down
8 changes: 2 additions & 6 deletions lib/jekyll-feed/meta-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def render(context)
private

def config
@context.registers[:site].config
@config ||= @context.registers[:site].config
end

def attributes
Expand All @@ -27,11 +27,7 @@ def attributes
end

def path
if config["feed"] && config["feed"]["path"]
config["feed"]["path"]
else
"feed.xml"
end
config.dig("feed", "path") || "feed.xml"
end

def title
Expand Down

0 comments on commit 2a82f18

Please sign in to comment.