Search code examples
rubyjekyllalgolia

Delete a key from a hash


I do not know Ruby at all but I am trying to extend this Jekyll plugin. The author mentions to just delete the key from the record. I've tried using the delete function but it doesn't seem to work.

Here's my code:

module Jekyll
  module Algolia
   module Hooks
     def self.before_indexing_each(record, node, context)
      record.delete(":gallery")
      record
     end
   end
  end
end

I am sure I am missing something very simple here but any ideas would be great. The hash looks like the following:

{:html=>"<p>Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).</p>", :content=>"Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).", :headings=>[], :custom_ranking=>{:position=>0, :heading=>100}, :title=>"Captain Brieux", :membership=>"Unconfirmed", :portrait=>"/gallery/members/captain-brieux/portrait.jpg", :attractions=>["_attractions/skipper-canteen.md"], :parks=>["Magic Kingdom", "Disneyland Paris"], :gallery=>[], :collection=>"members", :tags=>[], :categories=>[], :excerpt_html=>"<p>Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).</p>", :excerpt_text=>"Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).", :slug=>"captain-brieux", :type=>"document", :url=>"/sea/members/captain-brieux"}

Solution

  • the problem that you are having in your code is that you are sending the symbol as string, just remove "" from the delete param

    module Jekyll
      module Algolia
       module Hooks
         def self.before_indexing_each(record, node, context)
          record.delete(:gallery)
          record
         end
       end
      end
    end