diff --git a/_plugins/2-generate_reviews.rb b/_plugins/2-generate_reviews.rb index 411d7dd..7e23170 100644 --- a/_plugins/2-generate_reviews.rb +++ b/_plugins/2-generate_reviews.rb @@ -34,6 +34,15 @@ module Jekyll # Add a string containing the review entries def generate_content(site) + # Creates a hash mapping paths to tournaments + tournaments = site.data['tournaments'] + path = tournaments.map do |entry| + entry['events'].map { |trn| entry['year'].to_s + "/" + trn['dir'].sub(/\/$/, '') } + end.flatten + trn = tournaments.map { |entry| entry['events'] }.flatten + @trn_hash = Hash[ path.zip(trn) ] + + # Creates review entries site.posts.reverse_each do |post| review_entry(site, post) unless post.data['pgn'].nil? end @@ -41,14 +50,14 @@ module Jekyll # Creates a review entry from the given post def review_entry(site, post) - # Creates the link to post + # Adds the link to post @buffer += "\n

" @buffer += "#{post.title}" @buffer += "

\n" @buffer += "
\n" - # Creates the date of post + # Adds the date of post post_date = localize(post.date, "%d %B %Y") @buffer += "
Дата:
#{post_date}
\n" @@ -59,21 +68,12 @@ module Jekyll year, tournament, basename = pgn.split '/' end - # Finds the tournament that the game was played in - catch :trn_found do - site.data['tournaments'].each do |entry| - entry['events'].each do |trn| - # Remove the trailing slash from the tournament directory if needed - if entry['year'] == year.to_i && trn['dir'].sub(/\/$/, '') == tournament - trn_link = "" + trn['title'] + "" - @buffer += "
Турнир:
#{trn_link}
\n" - throw :trn_found - end - end - end - end + # Adds the tournament of the game + trn = @trn_hash[ year + "/" + tournament ] + trn_link = "" + trn['title'] + "" + @buffer += "
Турнир:
#{trn_link}
\n" - # Creates the game info + # Adds the game info white, black = basename[11..-1].sub(/-with-comments\.pgn$/, '').split('-vs-') white_link = "#{white}" black_link = "#{black}"