diff --git a/app/helpers/crops_helper.rb b/app/helpers/crops_helper.rb index 3519f4324..e5ec348ef 100644 --- a/app/helpers/crops_helper.rb +++ b/app/helpers/crops_helper.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true module CropsHelper - def crop_or_parent(crop, attribute) default = crop.send(attribute) return default if default.present? + parent = crop - while parent = parent.parent do + while parent = parent.parent return parent.send(attribute) if parent&.send(attribute).present? end @@ -38,4 +38,13 @@ module CropsHelper match = url.match(regex) match[1] if match end + + def jsonld_data(crop) + { + '@context': "https://schema.org", + '@type': "BioChemEntity", + name: crop.name, + taxonomicRange: crop.scientific_names.map(&:name) + } + end end