私はRubyの初心者で、このコードを理解するのに苦労しています
require_relative 'custom_page'
module Jekyll
class Tag < CustomPage
def initialize(site, base, dir, tag)
super site, base, dir, 'tag'
self.data['tag'] = tag
self.data['title'] = "#{site.config['tag_title_prefix'] || 'Tag: '}#{tag}"
self.data['description'] = "#{site.config['tag_meta_description_prefix'] || 'Tag: '}#{tag}"
end
end
class Tags < CustomPage
def initialize(site, base, dir)
super site, base, dir, 'tags'
self.data['tags'] = site.categories.keys.sort
#1# puts self.data['tags']
end
end
class Site
# generate_tags_categories is called by the custom process function in site_process.rb
def generate_tags_categories
dir = self.config['tag_dir'] || 'tags'
write_page Tags.new(self, self.source, dir) if self.layouts.key? 'tags'
self.categories.keys.each do |tag|
puts "dd"
#2# puts tag
write_page Tag.new(self, self.source, File.join(dir, tag.slugize), tag)
end
end
end
end
上記のコードでは、ステートメントputs self.data['tags']
(1 とマークされています) は、予想どおり 10 を超える値を出力します。ただし、行puts tag
(2 とマーク) は 1 つの値のみを出力し、配列に値が 1 つしか含まれていないことを意味します。self.categories.keys.each
それ自体が割り当てられているすべての値をループすることは期待されていませんself.data['tags']