lib/bolognese/readers/schema_org_reader.rb in bolognese-0.9.95 vs lib/bolognese/readers/schema_org_reader.rb in bolognese-0.9.96

- old
+ new

@@ -14,11 +14,11 @@ return { "string" => nil, "state" => "not_found" } unless id.present? id = normalize_id(id) response = Maremma.get(id) doc = Nokogiri::XML(response.body.fetch("data", nil), nil, 'UTF-8') - #string = doc.at_xpath('//script[@type="application/ld+json"]') + # workaround for xhtml documents nodeset = doc.css("script") string = nodeset.find { |element| element["type"] == "application/ld+json" } string = string.text if string.present? @@ -31,11 +31,11 @@ return { "errors" => errors } if errors.present? end meta = string.present? ? Maremma.from_json(string) : {} - id = normalize_id(meta.fetch("@id", nil) || options[:id]) + id = normalize_id(meta.fetch("@id", nil) || meta.fetch("identifier", nil)) type = meta.fetch("@type", nil) && meta.fetch("@type").camelcase resource_type_general = Bolognese::Utils::SO_TO_DC_TRANSLATIONS[type] authors = meta.fetch("author", nil) || meta.fetch("creator", nil) author = get_authors(from_schema_org(Array.wrap(authors))) editor = get_authors(from_schema_org(Array.wrap(meta.fetch("editor", nil)))) @@ -63,14 +63,16 @@ "citeproc_type" => Bolognese::Utils::SO_TO_CP_TRANSLATIONS[type] || "article-journal", "bibtex_type" => Bolognese::Utils::SO_TO_BIB_TRANSLATIONS[type] || "misc", "ris_type" => Bolognese::Utils::SO_TO_RIS_TRANSLATIONS[resource_type_general.to_s.dasherize] || "GEN", "resource_type_general" => resource_type_general, "doi" => validate_doi(id), + "identifier" => id, "b_url" => normalize_id(meta.fetch("url", nil)), "title" => meta.fetch("name", nil), "alternate_name" => meta.fetch("alternateName", nil), "author" => author, - "publisher" => meta.dig("publisher", "name"), + "editor" => editor, + "publisher" => publisher, "service_provider" => meta.fetch("provider", nil), "is_identical_to" => schema_org_is_identical_to(meta), "is_part_of" => is_part_of, "has_part" => schema_org_has_part(meta), "references" => schema_org_references(meta),